isCompress = $system['compress'] ?? true; } $this->validate = new VUpload(); $this->uploadPath = Config::get('filesystem.disks.local.url'); if(is_writable(app()->getRootPath() . 'public' . $this->uploadPath)){ $this->uploadPathIsWritable = true; } $this->cancelTimeLimit(); } /** * 通用文件上传 * @return Json */ public function file() { $file = request()->file('file'); if (empty($file)) { return $this->json(4001, '请上传的文件'); } if($this->validate->checkFile($file)){ try{ if(!$this->uploadPathIsWritable){ throw new \Exception('上传文件夹需要写入权限'); } $src = Filesystem::putFile('files/'.date('Ym'), $file, 'uniqid'); $src = $this->uploadPath . '/' . $src; $return['src'] = $src; $return['name'] = $file->getOriginalName(); //加入上传文件表 File::add($file, $src, $file->md5()); } catch (\Exception $e) { return $this->json(4003, $e->getMessage()); } return $this->json(0,'success', $return); }else{ $errorMsg = Lang::get($this->validate->getError()); return $this->json(4002, $errorMsg); } } /** * 通用图片上传 * @return Json */ public function image() { $image = request()->file('image'); if (empty($image)) { return $this->json(4001, '请上传图片文件'); } $md5 = $image->md5();//文件md5 if($this->validate->checkImage($image)){ try{ if(!$this->uploadPathIsWritable){ throw new \Exception('上传文件夹需要写入权限'); } $src = Filesystem::putFile('images/'.date('Ym'), $image, 'uniqid'); $src = $this->uploadPath . '/' . $src; $return['src'] = $src; if($this->isCompress){ Image::resize($src); } //加入上传文件表 File::add($image, $src,$md5); } catch (\Exception $e) { return $this->json(4003, $e->getMessage()); } return $this->json(0, 'success', $return); }else{ $errorMsg = Lang::get($this->validate->getError()); return $this->json(4002, $errorMsg); } } /** * 同步到OOS服务器存储 * @param string $src */ private function syncToOos(string $src) { } }