You are here

protected function Upload::getFullName in UEditor - 百度编辑器 8

重命名文件

Return value

string

3 calls to Upload::getFullName()
UploadCatch::doUpload in src/Uploader/UploadCatch.php
UploadFile::doUpload in src/Uploader/UploadFile.php
UploadScrawl::doUpload in src/Uploader/UploadScrawl.php

File

src/Uploader/Upload.php, line 140

Class

Upload
UEditor编辑器通用上传类

Namespace

Drupal\ueditor\Uploader

Code

protected function getFullName() {

  //替换日期事件
  $t = time();
  $d = explode('-', date("Y-y-m-d-H-i-s"));
  $format = $this->config["pathFormat"];
  $format = str_replace("{yyyy}", $d[0], $format);
  $format = str_replace("{yy}", $d[1], $format);
  $format = str_replace("{mm}", $d[2], $format);
  $format = str_replace("{dd}", $d[3], $format);
  $format = str_replace("{hh}", $d[4], $format);
  $format = str_replace("{ii}", $d[5], $format);
  $format = str_replace("{ss}", $d[6], $format);
  $format = str_replace("{time}", $t, $format);

  //过滤文件名的非法自负,并替换文件名
  $oriName = substr($this->oriName, 0, strrpos($this->oriName, '.'));
  $oriName = preg_replace("/[\\|\\?\"\\<\\>\\/\\*\\\\]+/", '', $oriName);
  $format = str_replace("{filename}", $oriName, $format);

  //替换随机字符串
  $randNum = rand(1, 10000000000) . rand(1, 10000000000);
  if (preg_match("/\\{rand\\:([\\d]*)\\}/i", $format, $matches)) {
    $format = preg_replace("/\\{rand\\:[\\d]*\\}/i", substr($randNum, 0, $matches[1]), $format);
  }

  //用Transliteration生成文件名
  if (strpos($format, '{transliteration_filename}')) {
    if (module_exists('transliteration') && function_exists('transliteration_clean_filename')) {
      $format = str_replace("{transliteration_filename}", transliteration_clean_filename($oriName), $format);
    }
  }
  $ext = $this
    ->getFileExt();
  return $format . $ext;
}