|
...
|
...
|
@@ -128,7 +128,7 @@ class ImageController extends Controller |
|
|
|
$type = $this->request->post('type','single');
|
|
|
|
$this->setUrl();
|
|
|
|
if ($type == 'multi') {
|
|
|
|
return $this->multi($files,$size,$image_type);
|
|
|
|
return $this->multi($files);
|
|
|
|
}else{
|
|
|
|
return $this->single($files,$size,$image_type);
|
|
|
|
}
|
|
...
|
...
|
@@ -142,7 +142,7 @@ class ImageController extends Controller |
|
|
|
* @method :post
|
|
|
|
* @time :2023/6/17 16:30
|
|
|
|
*/
|
|
|
|
public function single($files,$size,$image_type){
|
|
|
|
public function single(&$files,$size,$image_type){
|
|
|
|
$hash = hash_file('md5', $files->getPathname());
|
|
|
|
//查看文件是否存在
|
|
|
|
$imageModel = new ImageModel();
|
|
...
|
...
|
@@ -213,13 +213,15 @@ class ImageController extends Controller |
|
|
|
* @method :post
|
|
|
|
* @time :2023/6/17 16:31
|
|
|
|
*/
|
|
|
|
private function multi($files) {
|
|
|
|
private function multi(&$files) {
|
|
|
|
if (!is_array($files)) {
|
|
|
|
$files = [$files];
|
|
|
|
}
|
|
|
|
$save_data = [];
|
|
|
|
$data = [];
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$size = $file->getSize();
|
|
|
|
$image_type = $file->getClientOriginalExtension();
|
|
|
|
$imageModel = new ImageModel();
|
|
|
|
$hash = hash_file('md5', $file->getPathname());
|
|
|
|
$image_hash = $imageModel->read(['hash'=>$hash]);
|
|
...
|
...
|
@@ -237,16 +239,16 @@ class ImageController extends Controller |
|
|
|
'path' => $this->path.'/'.$fileName,
|
|
|
|
'created_at' => date('Y-m-d H:i:s',time()),
|
|
|
|
'updated_at'=>date('Y-m-d H:i:s',time()),
|
|
|
|
'size' => $res->getSize(),
|
|
|
|
'size' => $size,
|
|
|
|
'hash' => $hash,
|
|
|
|
'type'=>$file->getClientOriginalExtension(),
|
|
|
|
'refer'=>$this->param['refer'] ?? '',
|
|
|
|
'type'=>$image_type,
|
|
|
|
'refer'=>$this->param['refer'] ?? 0,
|
|
|
|
];
|
|
|
|
$data[] = ['image'=>$hash];
|
|
|
|
//同步数据到cos
|
|
|
|
if($this->upload_location == 1){
|
|
|
|
$cosService = new CosService();
|
|
|
|
$cosService->uploadFile($this->path,$fileName);
|
|
|
|
$cosService->uploadFile($file,$this->path,$fileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$imageModel->insert($save_data);
|
...
|
...
|
|