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

 <img src="/UploadFiles/2021-04-02/'.$company->picpath_) }}">

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,上传,图片,显示

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com