where("id",1)->find(); $file = $request->file('file'); $code = $request->post("code","image"); if(empty($file)) { return app('json')->fail("未上传文件"); } if(!in_array($code, ["image","advert","goods","activity"])){ return app('json')->fail("上传路径错误"); } $ext = $file->extension(); if(!in_array($ext, array("png","jpeg","gif","jpg"))){ return app('json')->fail("图片类型错误"); } $upPath = \think\facade\Filesystem::disk('resource')->putFile( $code, $file); if(!$upPath){ return app('json')->fail("图片上传失败01"); } $savePath = $sysData['system_url'].'/resource/' . $upPath; $imgUrl = str_replace("\\", "/", $savePath); return app('json')->success(['img'=>$imgUrl]); } /** * 上传文件 * @param Request $request */ public function uploadFile(Request $request){ $fileType = $request->post('type',''); $file =$request->file('file'); if(empty($file)) { return app('json')->fail("未上传文件"); } //上传文件夹选择 if(!in_array($fileType,["animated"])){ return app('json')->fail("请选择上传文件夹"); } $rootTmp = config('filesystem.disks.local.root') .'/' . \think\facade\Filesystem::putFile( 'tmp', $file); $qiniu = new Qiniu; $file_url = $qiniu->pathFileUpload($fileType, $rootTmp, $rootTmp); if(empty($file_url['url'])){ return app('json')->fail( $qiniu->getError()); } return app('json')->success(['url'=>$file_url['url']]); } /** * 上传视频 * @param Request $request */ public function mp4(Request $request) { $file = $request->file('Filedata'); if(empty($file)) { return app('json')->fail('上传失败'); } $name = $file->getOriginalName(); $expAr= explode('.',$name); $exp = end($expAr); $dEXp = ['mp4']; if(!in_array(strtolower($exp),$dEXp)) { return app('json')->fail('上传格式不支持.'.$exp); } $mp4up = new upMp4([ 'file' => 'Filedata', 'checkTmpRoot' => config('filesystem.disks.local.root') . "/mp4/", 'mp4Root' => config('filesystem.disks.local.root') . "/mp4/" ]); $mp4up->setParam($request->param()); $b = $mp4up->render('jpg'); if ($b) { $return = $mp4up->getResult(); return app('json')->success($return); } return app('json')->fail( $mp4up->getError()); } }