laravel实现上传图片并在页面显示的例子,图片,上传,路由,上传图片,位置
laravel实现上传图片并在页面显示的例子
易采站长站,站长之家为您整理了laravel实现上传图片并在页面显示的例子的相关内容。
1:上传图片public function updateFeedbackImg(Request $request) { $bool = false; $upload_file = $request->file("pic"); if ($upload_file->isValid()) { $realPath = $upload_file->getRealPath(); $bool = Storage::disk('feedback')->put($request->get('id') . '.png', file_get_contents($realPath)); } if ($bool == true) { $company = CompanyState::find($request->get('id')); $company->picpath_ = $request->get('id') . '.png'; $company->save(); return '{"statusCode":"200", "message":"上传成功", "navTabId":"uploadFeedbackImg", "forwardUrl":"evaluation/queryCompanyFeedback/' . session('plan_id') . '","callbackType":"forward"}'; } else { return '{"statusCode":"300", "message":"上传失败","callbackType":"closeCurrent"}'; } }
2:html
3:设置对应的路由Route::group(['prefix' => 'evaluation'], function () { //查看图片Route::get('/lookthrough/{company_id}', 'EvaluationController@lookthrough');//放大图片Route::get('/showImage/{src}', 'EvaluationController@showImage');});
4:显示图片public function lookthrough($company_id) { $company = CompanyState::getRecordById($company_id); return view('panels.EvaluationManagement.FeedbackInfo.FeedbackImg', ['company' => $company[0]]); } public function showImage($src) { $path = storage_path() . '/feedback/' . $src; //获取图片位置的方法 return response()->file($path); }以上就是关于对laravel实现上传图片并在页面显示的例子的详细介绍。欢迎大家对laravel实现上传图片并在页面显示的例子内容提出宝贵意见