侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

laravel实现上传图片并在页面显示的例子

2022-06-14 星期二 / 0 评论 / 0 点赞 / 134 阅读 / 2097 字

1:上传图片public function updateFeedbackImg(Request $request) { $bool = false; $upload_file = $request->fil

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:设置对应的路由

.
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上传图片显示就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持..。

广告 广告

评论区