欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

laravel實(shí)現(xiàn)上傳圖片并在頁面顯示的例子

 更新時(shí)間:2019年10月14日 09:18:25   作者:上官hao  
今天小編就為大家分享一篇laravel實(shí)現(xiàn)上傳圖片并在頁面顯示的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

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="{{ url('evaluation/showImage/'.$company->picpath_) }}"
     οnclick="this.width+=500;this.height+=500; javascript:window.open(this.src);"
     style="cursor:pointer; width: 500px; height: 800px;border:1px solid #000000"
     name="photopath"/>

3:設(shè)置對(duì)應(yīng)的路由

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上傳圖片顯示就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論