首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Laravel5.2中获取图像

问在Laravel5.2中获取图像
EN

Stack Overflow用户
提问于 2017-04-17 11:06:19
回答 1查看 744关注 0票数 2

我在storage->app->upload->images->1472803410756.jpg上有一张图片。当我键入url http://localhost:8012/demo/storage/app/upload/images/1472803410756.jpg时,浏览器会准确地显示我的图像。但是运行php artisan serve,url:http://localhost:8000/storage/app/upload/images/1472803410756.jpg浏览器没有找到我的图像。怎么才能修好呢?

我的html代码:

代码语言:javascript
复制
<td><img class="table_image"  src="{{asset("storage/app/upload/images/$product->product_image")}}"></td>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-17 11:50:08

这是错误的,您从仅具有写权限的存储folder.Because存储文件夹中获取映像。因此,首先您需要创建存储路径的路由。

代码语言:javascript
复制
enter code here
Route::get('storage/{filename}', function ($filename)
{
    $path = storage_path('app/upload/images/' . $filename);

    if (!File::exists($path)) {
        abort(404);
    }

    $file = File::get($path);
    $type = File::mimeType($path);

    $response = Response::make($file, 200);
    $response->header("Content-Type", $type);
    return $response;
});

在那之后,你的img标签看起来是这样的:-

代码语言:javascript
复制
<td><img class="table_image"  src="{{url("storage/".$product->product_image)}}"></td>

希望能帮上忙!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43450234

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档