作者 lyh

gx

... ... @@ -3,10 +3,12 @@
namespace App\Http\Logic\Bside;
use App\Enums\Common\Code;
use App\Enums\Common\Common;
use App\Exceptions\BsideGlobalException;
use App\Http\Controllers\file\ImageController;
use App\Http\Logic\Logic;
use App\Models\File\Image as ImageModel;
use Illuminate\Support\Facades\Cache;
/**
... ... @@ -99,9 +101,32 @@ class BaseLogic extends Logic
* @method
*/
public function upload(){
$image = new ImageController();
$data = $image->upload();
return $data['data']['image'];
$files = $this->request->file('image');
$hash = hash_file('md5', $files->getPathname());
//查看文件是否存在
$imageModel = new ImageModel();
$image_hash = $imageModel->read(['hash'=>$hash]);
if($image_hash !== false){
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]);
}
$url = $this->path;
$fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
$res = $files->move($url,$fileName);
if ($res === false) {
return false;
}
$data = [
'path' => $url.$fileName,
'created_at' => date('Y-m-d H:i:s',time()),
'size' => $res->getSize(),
'hash' => $hash,
'type'=>$files->getClientOriginalExtension(),
];
$rs = $imageModel->add($data);
if ($rs === false) {
return false;
}
return $hash;
}
/**
... ...