Search code examples
laravellaravel-5eloquent

Laravel Storage File not downloading (File not found)


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"]

Solution

  • 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.