isCompress = $system['compress'] ?? true; } $this->validate = new VUpload(); $this->uploadPath = Config::get('filesystem.disks.local.url'); $savePath = app()->getRootPath() . 'public' . $this->uploadPath; if (!is_dir($savePath)) { @mkdir($savePath, 0777); } if(is_writable($savePath)){ $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(date('Ymd'), $file, 'uniqid'); $src = $this->uploadPath . '/' . $src; $return['src'] = $src; $return['name'] = $file->getOriginalName(); } 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, '请上传图片文件'); } if($this->validate->checkImage($image)){ try{ if(!$this->uploadPathIsWritable){ throw new \Exception('上传文件夹需要写入权限'); } $src = Filesystem::putFile(date('Ymd'), $image, 'uniqid'); $src = $this->uploadPath . '/' . $src; $return['src'] = $src; if($this->isCompress){ Image::resize($src); } } 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); } } }