1.新增方法、crmeb\basic\BaseUpload.php
/**
* 文件是否在本地
* @param string $filePath
* @return bool
*/
protected function isLocal(string $filePath)
{
$isLocal = false;
$path = $filePath;
$data = parse_url($path);
//远程地址处理
if (isset($data['host']) && isset($data['path'])) {
if (file_exists(app()->getRootPath() . 'public' . $data['path'])) {
$isLocal = true;
}
}
return $isLocal;
}
- 修改crmeb\services\upload\storage\Local.php
public function image(string $filePath, array $waterConfig = [], string $waterPath = '') { if (!$waterConfig) { $waterConfig = $this->waterConfig; } $watermark_image = $waterConfig['watermark_image']; //远程图片 if ($watermark_image && $this->checkFilePathIsRemote($watermark_image)) { //看是否在本地 if (!$this->isLocal($watermark_image)) {//不再本地 继续下载##修改了这一行 [$p, $e] = $this->getFileName($watermark_image); $name = 'water_image_' . md5($watermark_image) . '.' . $e; $watermark_image = $this->defaultPath . '/' . $this->thumbWaterPath . '/' . $name;##修改了这一行 if (!file_exists(root_path() . 'public' . $watermark_image)) { try { /** @var DownloadImageService $down */ $down = app()->make(DownloadImageService::class); $data = $down->path($this->thumbWaterPath)->downloadImage($waterConfig['watermark_image'], $name); $watermark_image = $data['path'] ?? ''; } catch (\Throwable $e) { throw new ValidateException('远程水印图片下载失败,原因:' . $e->getMessage()); } } } else { $watermark_image = $this->getFilePath($watermark_image, true);##修改了这一行 } } if (!$watermark_image) { throw new ValidateException('请先配置水印图片'); } if (!$waterPath) { [$path, $ext] = $this->getFileName($filePath); $waterPath = $path . '_water_image.' . $ext; } try { if (!file_exists(root_path() . 'public' . $waterPath)) { $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);##修改了这一行 } } catch (\Throwable $e) { throw new ValidateException($e->getMessage()); } return $waterPath; }
可以下载附件,放在项目目录内的crmeb目录下进行解压