【问题标题】:how to see uploaded image in web browser in laravel lumen?如何在 laravel lumen 的网络浏览器中查看上传的图像?
【发布时间】:2016-01-11 06:33:07
【问题描述】:

你能帮我解决一些愚蠢的问题吗:( 我已经在 project-root/storage/products 下的 laravel lumen 中上传了图片 但我不知道如何在浏览器中查看上传的图片,我的存储文件夹在公共目录之外,我试过了

http://192.168.11.102:8000/storage/products/upc_1443002080.jpg
http://192.168.11.102:8000/index.php/storage/products/upc_1443002080.jpg

但是我得到了 - 抱歉,找不到您要查找的页面。您能帮帮我吗?

更新 正如你所说,我已经创建了这样的路线 -

$app->get('products/{filename}', function ($filename) {
$path = storage_path().'/products/'.$filename;

if (file_exists($path)) {
    return Response::download($path);
}});

但是当我点击http://192.168.11.102:8000/storage/products/upc_1443002080.jpg 它正在下载文件而不是显示在浏览器中。你有什么主意吗? 我在 Response::download 函数中有以下代码 -

public static function download($file, $name = null, array $headers = [], $disposition = 'attachment')
{
    $response = new BinaryFileResponse($file, 200, $headers, true, $disposition);
    if (! is_null($name)) {
        return $response->setContentDisposition($disposition, $name, str_replace('%', '', Str::ascii($name)));
    }
    return $response;
}

【问题讨论】:

    标签: laravel lumen


    【解决方案1】:

    存储目录中存储的文件受到保护。文档根目录是 /public。要在浏览器中查看上传的项目,您需要创建一个接受文件名的路由,然后控制器将获取该文件。

    【讨论】:

      猜你喜欢
      • 2021-12-26
      • 1970-01-01
      • 2012-08-25
      • 1970-01-01
      • 1970-01-01
      • 2013-10-23
      • 2021-08-21
      • 2020-05-23
      • 1970-01-01
      相关资源
      最近更新 更多