diff --git a/.gitignore b/.gitignore index 011ca6a2..b2091311 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ /vendor/ /runtime/* /addons/* -/application/admin/command/Install/*.lock /public/assets/libs/ /public/assets/addons/* /public/uploads/* diff --git a/application/common/library/Upload.php b/application/common/library/Upload.php index ea2ac44e..77db11bf 100644 --- a/application/common/library/Upload.php +++ b/application/common/library/Upload.php @@ -150,7 +150,7 @@ class Upload $typeDict = ['b' => 0, 'k' => 1, 'kb' => 1, 'm' => 2, 'mb' => 2, 'gb' => 3, 'g' => 3]; $size = (int)($size * pow(1024, isset($typeDict[$type]) ? $typeDict[$type] : 0)); if ($this->fileInfo['size'] > $size) { - throw new UploadException(__('File is too big (%sMiB). Max filesize: %sMiB.', + throw new UploadException(__('File is too big (%sMiB), Max filesize: %sMiB.', round($this->fileInfo['size'] / pow(1024, 2), 2), round($size / pow(1024, 2), 2))); } @@ -167,35 +167,41 @@ class Upload /** * 获取存储的文件名 - * @param string $savekey - * @param string $filename - * @param string $md5 + * @param string $savekey 保存路径 + * @param string $filename 文件名 + * @param string $md5 文件MD5 + * @param string $category 分类 * @return mixed|null */ - public function getSavekey($savekey = null, $filename = null, $md5 = null) + public function getSavekey($savekey = null, $filename = null, $md5 = null, $category = null) { if ($filename) { $suffix = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); - $suffix = $suffix && preg_match("/^[a-zA-Z0-9]+$/", $suffix) ? $suffix : 'file'; } else { - $suffix = $this->fileInfo['suffix']; + $suffix = $this->fileInfo['suffix'] ?? ''; } - $filename = $filename ? $filename : ($suffix ? substr($this->fileInfo['name'], 0, strripos($this->fileInfo['name'], '.')) : $this->fileInfo['name']); + $suffix = $suffix && preg_match("/^[a-zA-Z0-9]+$/", $suffix) ? $suffix : 'file'; + $filename = $filename ? $filename : ($this->fileInfo['name'] ?? 'unknown'); $filename = xss_clean(strip_tags(htmlspecialchars($filename))); - $md5 = $md5 ? $md5 : md5_file($this->fileInfo['tmp_name']); + $fileprefix = substr($filename, 0, strripos($filename, '.')); + $md5 = $md5 ? $md5 : (isset($this->fileInfo['tmp_name']) ? md5_file($this->fileInfo['tmp_name']) : ''); + $category = $category ? $category : request()->post('category'); + $category = $category ? xss_clean($category) : 'all'; $replaceArr = [ - '{year}' => date("Y"), - '{mon}' => date("m"), - '{day}' => date("d"), - '{hour}' => date("H"), - '{min}' => date("i"), - '{sec}' => date("s"), - '{random}' => Random::alnum(16), - '{random32}' => Random::alnum(32), - '{filename}' => substr($filename, 0, 100), - '{suffix}' => $suffix, - '{.suffix}' => $suffix ? '.' . $suffix : '', - '{filemd5}' => $md5, + '{year}' => date("Y"), + '{mon}' => date("m"), + '{day}' => date("d"), + '{hour}' => date("H"), + '{min}' => date("i"), + '{sec}' => date("s"), + '{random}' => Random::alnum(16), + '{random32}' => Random::alnum(32), + '{category}' => $category ? $category : '', + '{filename}' => substr($filename, 0, 100), + '{fileprefix}' => substr($fileprefix, 0, 100), + '{suffix}' => $suffix, + '{.suffix}' => $suffix ? '.' . $suffix : '', + '{filemd5}' => $md5, ]; $savekey = $savekey ? $savekey : $this->config['savekey']; $savekey = str_replace(array_keys($replaceArr), array_values($replaceArr), $savekey); diff --git a/application/config.php b/application/config.php index 5f3f6dad..2f09465f 100755 --- a/application/config.php +++ b/application/config.php @@ -201,6 +201,7 @@ return [ 'type' => '', // 是否自动开启 SESSION 'auto_start' => true, + //'cache_limiter'=>'' ], // +---------------------------------------------------------------------- // | Cookie设置 @@ -296,7 +297,7 @@ return [ //允许跨域的域名,多个以,分隔 'cors_request_domain' => 'localhost,127.0.0.1', //版本号 - 'version' => '1.3.4.20220530', + 'version' => '1.3.5.20221214', //API接口地址 'api_url' => 'https://api.fastadmin.net', ], diff --git a/application/extra/upload.php b/application/extra/upload.php index 061ca85e..b9d2c4ea 100644 --- a/application/extra/upload.php +++ b/application/extra/upload.php @@ -21,7 +21,7 @@ return [ /** * 可上传的文件类型 */ - 'mimetype' => 'jpg,png,bmp,jpeg,gif,webp,zip,rar,xls,xlsx,wav,mp4,mp3,webm,pdf', + 'mimetype' => 'jpg,png,bmp,jpeg,gif,webp,zip,rar,wav,mp4,mp3,webm', /** * 是否支持批量上传 */