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?
// 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.