框架升级及修复升级后的bug
This commit is contained in:
@@ -86,6 +86,11 @@ class Upload
|
||||
*/
|
||||
protected function checkExecutable()
|
||||
{
|
||||
//禁止上传以.开头的文件
|
||||
if (substr($this->fileInfo['name'], 0, 1) === '.') {
|
||||
throw new UploadException(__('Uploaded file format is limited'));
|
||||
}
|
||||
|
||||
//禁止上传PHP和HTML文件
|
||||
if (in_array($this->fileInfo['type'], ['text/x-php', 'text/html']) || in_array($this->fileInfo['suffix'], ['php', 'html', 'htm', 'phar', 'phtml']) || preg_match("/^php(.*)/i", $this->fileInfo['suffix'])) {
|
||||
throw new UploadException(__('Uploaded file format is limited'));
|
||||
@@ -107,8 +112,7 @@ class Upload
|
||||
throw new UploadException(__('Uploaded file format is limited'));
|
||||
}
|
||||
//验证文件后缀
|
||||
if ($this->config['mimetype'] === '*'
|
||||
|| in_array($this->fileInfo['suffix'], $mimetypeArr) || in_array('.' . $this->fileInfo['suffix'], $mimetypeArr)
|
||||
if (in_array($this->fileInfo['suffix'], $mimetypeArr) || in_array('.' . $this->fileInfo['suffix'], $mimetypeArr)
|
||||
|| in_array($typeArr[0] . "/*", $mimetypeArr) || (in_array($this->fileInfo['type'], $mimetypeArr) && stripos($this->fileInfo['type'], '/') !== false)) {
|
||||
return true;
|
||||
}
|
||||
@@ -347,82 +351,6 @@ class Upload
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通上传
|
||||
* @return \app\common\model\attachment|\think\Model
|
||||
* @throws UploadException
|
||||
*/
|
||||
public function uploadFile($savekey = null)
|
||||
{
|
||||
if (empty($this->file)) {
|
||||
throw new UploadException(__('No file upload or server upload limit exceeded'));
|
||||
}
|
||||
|
||||
$this->checkSize();
|
||||
$this->checkExecutable();
|
||||
$this->checkMimetype();
|
||||
$this->checkImage();
|
||||
|
||||
$savekey = $savekey ? $savekey : $this->getSavekey();
|
||||
$savekey = '/' . ltrim($savekey, '/');
|
||||
$uploadDir = substr($savekey, 0, strripos($savekey, '/') + 1);
|
||||
$fileName = substr($savekey, strripos($savekey, '/') + 1);
|
||||
|
||||
$destDir = ROOT_PATH . 'public' . str_replace('/', DS, $uploadDir);
|
||||
|
||||
$sha1 = $this->file->hash();
|
||||
|
||||
//如果是合并文件
|
||||
if ($this->merging) {
|
||||
if (!$this->file->check()) {
|
||||
throw new UploadException($this->file->getError());
|
||||
}
|
||||
$destFile = $destDir . $fileName;
|
||||
$sourceFile = $this->file->getRealPath() ?: $this->file->getPathname();
|
||||
$info = $this->file->getInfo();
|
||||
$this->file = null;
|
||||
if (!is_dir($destDir)) {
|
||||
@mkdir($destDir, 0755, true);
|
||||
}
|
||||
rename($sourceFile, $destFile);
|
||||
$file = new File($destFile);
|
||||
$file->setSaveName($fileName)->setUploadInfo($info);
|
||||
} else {
|
||||
$file = $this->file->move($destDir, $fileName);
|
||||
if (!$file) {
|
||||
// 上传失败获取错误信息
|
||||
throw new UploadException($this->file->getError());
|
||||
}
|
||||
}
|
||||
$this->file = $file;
|
||||
$category = request()->post('category');
|
||||
$category = array_key_exists($category, config('site.attachmentcategory') ?? []) ? $category : '';
|
||||
$auth = Auth::instance();
|
||||
$params = array(
|
||||
'admin_id' => (int)session('admin.id'),
|
||||
'user_id' => (int)$auth->id,
|
||||
'filename' => mb_substr(htmlspecialchars(strip_tags($this->fileInfo['name'])), 0, 100),
|
||||
'category' => $category,
|
||||
'filesize' => $this->fileInfo['size'],
|
||||
'imagewidth' => $this->fileInfo['imagewidth'],
|
||||
'imageheight' => $this->fileInfo['imageheight'],
|
||||
'imagetype' => $this->fileInfo['suffix'],
|
||||
'imageframes' => 0,
|
||||
'mimetype' => $this->fileInfo['type'],
|
||||
'url' => $uploadDir . $file->getSaveName(),
|
||||
'uploadtime' => time(),
|
||||
'storage' => 'local',
|
||||
'sha1' => $sha1,
|
||||
'extparam' => '',
|
||||
);
|
||||
$attachment = new Attachment();
|
||||
$attachment->data(array_filter($params));
|
||||
$attachment->save();
|
||||
|
||||
\think\Hook::listen("upload_after", $attachment);
|
||||
return $attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通上传
|
||||
* @return \app\common\model\attachment|\think\Model
|
||||
|
||||
Reference in New Issue
Block a user