|
@@ -127,15 +127,18 @@ class Local extends BaseUpload
|
|
|
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('文件内容不合法');
|
|
|
-// }
|
|
|
- $fileType = pathinfo($fileHandle->getOriginalName(), PATHINFO_EXTENSION);
|
|
|
+ if(!$this->checkImage($fileHandle)) {
|
|
|
+ $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('文件内容不合法');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $fileType = pathinfo($fileHandle->getOriginalName(), PATHINFO_EXTENSION);
|
|
|
+
|
|
|
$fileName = Filesystem::putFileAs($this->path, $fileHandle, in_array($fileType, ['ico']) ? $fileHandle->getOriginalName() : strtolower($fileHandle->hashName()));
|
|
|
|
|
|
if (!$fileName)
|
|
@@ -239,12 +242,12 @@ class Local extends BaseUpload
|
|
|
$savePath = $this->createSaveFilePath($filePath, $this->thumbWaterPath, [$height => $config[$height], $width => $config[$width]]);
|
|
|
//防止重复生成
|
|
|
if (!file_exists(root_path() . 'public' . $savePath)) {
|
|
|
- if ($this->authThumb) {//生成
|
|
|
- $Image = Image::open(app()->getRootPath() . 'public' . $filePath);
|
|
|
- $Image->thumb($config[$width], $config[$height])->save(root_path() . 'public' . $savePath);
|
|
|
- } else {
|
|
|
- $savePath = $filePath;
|
|
|
- }
|
|
|
+ if ($this->authThumb) {//生成
|
|
|
+ $Image = Image::open(app()->getRootPath() . 'public' . $filePath);
|
|
|
+ $Image->thumb($config[$width], $config[$height])->save(root_path() . 'public' . $savePath);
|
|
|
+ } else {
|
|
|
+ $savePath = $filePath;
|
|
|
+ }
|
|
|
}
|
|
|
$key = 'filePath' . ucfirst($v);
|
|
|
$data[$v] = $this->fileInfo->$key = $savePath;
|
|
@@ -327,12 +330,12 @@ class Local extends BaseUpload
|
|
|
}
|
|
|
try {
|
|
|
if (!file_exists(root_path() . 'public' . $waterPath)) {
|
|
|
- if ($this->authThumb) {//生成
|
|
|
- $Image = Image::open(app()->getRootPath() . 'public' . $filePath);
|
|
|
- $Image->water(app()->getRootPath() . 'public' . $watermark_image, $waterConfig['watermark_position'] ?: 1, $waterConfig['watermark_opacity'])->save(root_path() . 'public' . $waterPath);
|
|
|
- } else {
|
|
|
- $waterPath = $filePath;
|
|
|
- }
|
|
|
+ if ($this->authThumb) {//生成
|
|
|
+ $Image = Image::open(app()->getRootPath() . 'public' . $filePath);
|
|
|
+ $Image->water(app()->getRootPath() . 'public' . $watermark_image, $waterConfig['watermark_position'] ?: 1, $waterConfig['watermark_opacity'])->save(root_path() . 'public' . $waterPath);
|
|
|
+ } else {
|
|
|
+ $waterPath = $filePath;
|
|
|
+ }
|
|
|
}
|
|
|
} catch (\Throwable $e) {
|
|
|
throw new ValidateException($e->getMessage());
|
|
@@ -361,19 +364,19 @@ class Local extends BaseUpload
|
|
|
}
|
|
|
try {
|
|
|
if (!file_exists(root_path() . 'public' . $waterPath)) {
|
|
|
- if ($this->authThumb) {//生成
|
|
|
- $Image = Image::open(app()->getRootPath() . 'public' . $filePath);
|
|
|
- if (strlen($waterConfig['watermark_text_color']) < 7) {
|
|
|
- $waterConfig['watermark_text_color'] = substr($waterConfig['watermark_text_color'], 1);
|
|
|
- $waterConfig['watermark_text_color'] = '#' . $waterConfig['watermark_text_color'] . $waterConfig['watermark_text_color'];
|
|
|
- }
|
|
|
- if (strlen($waterConfig['watermark_text_color']) > 7) {
|
|
|
- $waterConfig['watermark_text_color'] = substr($waterConfig['watermark_text_color'], 0, 7);
|
|
|
- }
|
|
|
- $Image->text($waterConfig['watermark_text'], $waterConfig['watermark_text_font'], $waterConfig['watermark_text_size'], $waterConfig['watermark_text_color'], $waterConfig['watermark_position'], [$waterConfig['watermark_x'], $waterConfig['watermark_y'], $waterConfig['watermark_text_angle']])->save(root_path() . 'public' . $waterPath);
|
|
|
- } else {
|
|
|
- $waterPath = $filePath;
|
|
|
- }
|
|
|
+ if ($this->authThumb) {//生成
|
|
|
+ $Image = Image::open(app()->getRootPath() . 'public' . $filePath);
|
|
|
+ if (strlen($waterConfig['watermark_text_color']) < 7) {
|
|
|
+ $waterConfig['watermark_text_color'] = substr($waterConfig['watermark_text_color'], 1);
|
|
|
+ $waterConfig['watermark_text_color'] = '#' . $waterConfig['watermark_text_color'] . $waterConfig['watermark_text_color'];
|
|
|
+ }
|
|
|
+ if (strlen($waterConfig['watermark_text_color']) > 7) {
|
|
|
+ $waterConfig['watermark_text_color'] = substr($waterConfig['watermark_text_color'], 0, 7);
|
|
|
+ }
|
|
|
+ $Image->text($waterConfig['watermark_text'], $waterConfig['watermark_text_font'], $waterConfig['watermark_text_size'], $waterConfig['watermark_text_color'], $waterConfig['watermark_position'], [$waterConfig['watermark_x'], $waterConfig['watermark_y'], $waterConfig['watermark_text_angle']])->save(root_path() . 'public' . $waterPath);
|
|
|
+ } else {
|
|
|
+ $waterPath = $filePath;
|
|
|
+ }
|
|
|
}
|
|
|
} catch (\Throwable $e) {
|
|
|
throw new ValidateException($e->getMessage() . $e->getLine());
|