in my laravel project i have uploads folder from where i am trying to download file.
Folder Hierarchy:
-Project
--Public
---Storage (created using php artisan storage:link)
----uploads
-----file.jpg ( i am trying to download)
Controller:
public function getdata(Request $request)
{
return Storage::download('/storage/uploads'.$image_name);
//image name is file.jpg
}
Error:
File not found at path: storage/uploads["file.jpg"]
CodePudding user response:
You can do like this
return Storage::disk('public')->download('uploads/'. $image_name);
CodePudding user response:
File not found at path: storage/uploads["file.jpg"]
[]
This shows you passing array in path
and also /
missing after uploads
Your path should be like below
storage/uploads/file.jpg
After above implementation your code would look like
Storage::download('/storage/uploads/'.$image_name);
Get Image from Database
$image_name = Files::select('file_name')->where('custom_code', $request->id)->first();
You can use ->first()
and image column accesible using $image_name->file_name
And In your way $image_name[0]
access like that.
CodePudding user response:
What you should do is something like this:
public function getdata(Request $request)
{
return Storage::download("uploads/" . $image_name['file_name']);
}
reference: https://laravel.com/docs/8.x/filesystem#downloading-files