【发布时间】: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;
}
【问题讨论】: