问题说明:文件上传是图片验证路径有误
修改文件:crmeb/services/upload/storage/Local.php
修改方法:move()
public function move(string $file = 'file', $realName = false)
{
$fileHandle = app()->request->file($file);
if (!$fileHandle) {
return $this->setError('Upload file does not exist');
}
if ($this->validate) {
try {
$error = [
$file . '.filesize' => 'Upload filesize error',
$file . '.fileExt' => 'Upload fileExt error',
$file . '.fileMime' => 'Upload fileMine error'
];
validate([$file => $this->validate], $error)->check([$file => $fileHandle]);
} catch (ValidateException $e) {
return $this->setError($e->getMessage());
}
}
// $stream = fopen($fileHandle->getPathname(), 'r');
// $content = (fread($stream, filesize($fileHandle->getPathname())));
// if (is_resource($stream)) {
// fclose($stream);
// }
// if (preg_match('/think|php|log|phar|Socket|Channel|Flysystem|Psr6Cache|Cached|Request|debug|Psr6Cachepool|eval/i', $content)) {
// return $this->setError('文件内容不合法');
// }
$disk ='public';
$path = $this->path;
$rule = null;
if (in_array($fileHandle->getOriginalMime(), ['application/x-x509-ca-cert', 'application/octet-stream'])) {
$disk = 'pem';
$path ='';
$rule = function() {
return md5(microtime(true));
};
}
$fileType = pathinfo($fileHandle->getOriginalName(), PATHINFO_EXTENSION);
$this->defaultPath = Config::get('filesystem.disks.' . $disk . '.url');
// $fileName = Filesystem::putFileAs($this->path, $fileHandle, in_array($fileType, ['ico']) ? $fileHandle->getOriginalName() : strtolower($fileHandle->hashName()));
if($realName) {
$fileName = Filesystem::disk($disk)->putFileAs($path, $fileHandle,$fileHandle->getoriginalName());
}else{
$fileName= Filesystem::disk($disk)->putFile($path, $fileHandle,$rule);
}
if (!$fileName)
return $this->setError('Upload failure');
$filePath = Filesystem::disk($disk)->path($fileName);
$this->fileInfo->uploadInfo = new File($filePath);
$this->fileInfo->realName = $fileHandle->getOriginalName();
$this->fileInfo->fileName = $this->fileInfo->uploadInfo->getFilename();
$this->fileInfo->filePath = $this->defaultPath . '/' . str_replace('\\', '/', $fileName);
if ($this->checkImage(public_path() . $this->fileInfo->filePath) && $this->authThumb && $fileType != 'ico' && $fileType != 'pem') {
try {
$this->thumb($this->fileInfo->filePath);
} catch (\Throwable $e) {
return $this->setError($e->getMessage());
}
}
return $this->fileInfo;
}
