首页 文章

如何在laravel流明的网页浏览器中查看上传的图像?

提问于
浏览
3

你可以帮我解决一些愚蠢的问题:(我已经在 project-root/storage/products 上载了laravel流明的图像但是我没试过't know how to check uploaded image in browser,my storage folder is outside public directory, I'

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

但是我得到了 - 抱歉,找不到你要找的页面 . 你能帮助我吗?

Update 正如你所说,我创造了这样的路线 -

$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;
}

1 回答

  • 1

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

相关问题