$code,'msg'=>$msg,'data'=>$data]; } //用户行为记录,暂时放这里具体用不用后期再加 public function user_log($data,$user,$id,$perm_id,$remark){ } //用于保存图片 public function save_pic(Request $request){ // 获取文件相关信息 $file = $request->file('file'); $ext = $file->getClientOriginalExtension(); // 扩展名 $realPath = $file->getRealPath(); //临时文件的绝对路径 $ext = strtolower($ext); $rule = ['jpg', 'png', 'gif', "jpeg"]; if (!in_array($ext, $rule)) { return '图片格式为jpg,png,gif'; } // 上传文件 $file_name = time().rand(1000,9999); $filename = $file_name.'.' . $ext; // 使用我们新建的uploads本地存储空间(目录) Storage::disk('public')->put('pic/'.$filename, file_get_contents($realPath)); return $this->json_return(200,'上传成功' ,['url'=>'/api/pic/'.$file_name]); } public function get_pic($file_name){ if(file_exists(storage_path().'/app/public/pic/'.$file_name.'.png')){ $ext = 'png'; }elseif(file_exists(storage_path().'/app/public/pic/'.$file_name.'.jpeg')){ $ext = 'jpeg'; }elseif(file_exists(storage_path().'/app/public/pic/'.$file_name.'.jpg')){ $ext = 'jpg'; }elseif(file_exists(storage_path().'/app/public/pic/'.$file_name.'.gif')){ $ext = 'gif'; }else{ $ext = 'xlsx'; // if(file_exists(storage_path().'/app/public/pic/basic/'.$file_name.'.gif')){ // return response()->file(storage_path().'/app/public/pic/'.$file_name.'.'.$ext); // }else{ // return response()->file(storage_path().'/app/public/pic/'.$file_name.'.'.$ext); // } } return response()->file(storage_path().'/app/public/pic/'.$file_name.'.'.$ext); } public function get_basic_pic($file_name){ return response()->file(storage_path().'/app/public/pic/basic/'.$file_name.'.png'); } }