Laravel回复下载

Laravel回复下载

问题描述:

I have the following file(picture) on my local :

http://localhost:8080/uploads/user/10230313465a9fb5e0e65a85.73871653.png

And i am using response()->download(path), The above path is stored in a DB table column. The exception comes :

The file http://localhost:8080/uploads/user/10230313465a9fb5e0e65a85.73871653.png does not exist

But by checking the file in the browser does show the uploaded photo. Which means the file exists

What am i missing here?

我在本地有以下文件(图片): p>

http:// localhost:8080 / uploads / user / 10230313465a9fb5e0e65a85.73871653.png code> p>

我正在使用 response() - >下载(路径 ) code>,上面的路径存储在DB表列中。 异常到来: p>

文件 http:// localhost:8080 / uploads / user / 10230313465a9fb5e0e65a85.73871653.png code>不存在 p> \ n

但通过检查浏览器中的文件确实显示上传的照片。 这意味着该文件存在 p>

我在这里缺少什么? p> div>

// Absolute path to file
$file = public_path() . 'uploads/user/10230313465a9fb5e0e65a85.73871653.png';

return response()->download($file);

Please ensure that the file is stored within the public folder of Laravel. Also, you could also do the following:

// Absolute path to file
$file = public_path() . 'uploads/user/10230313465a9fb5e0e65a85.73871653.png';

if (! is_file($file)) {
    // File can not be found
    abort(404);
}

return response()->download($file);

This is a more appropriate response to return if the file can not be found.

I hope this helps.