Download file from database (storage)

Posted 3 months ago by ziben69

Hello guys,

I did multiple file upload: model File:

class File extends Model
{
    protected $fillable = [
        'title',
        'description',
        'filename'
    ];
}

FileController (store function):

  public function storeFiles(Request $request)
    {

        $this->validate($request, [
            'filename' => 'required',
            'filename.*' => 'mimes:doc,pdf,docx,zip'
        ]);


        if($request->hasfile('filename'))
        {
            foreach($request->file('filename') as $file)
            {
                $name=$file->getClientOriginalName();
                $file->move(storage_path('/app/public/files/', $name));
                $data[] = $name;  
            }
        }

        $file = new File();
        $file->title = $request->input('title');
        $file->description = $request->input('description');
        $file->filename=json_encode($data);   
        $file->save();

        return redirect()->action('[email protected]');
    }

and how can I download file now. I have something like this:

public function show($id)
    {
        $dl = File::find($id);
        return Storage::download(storage_path('app/public/files/'), $dl->filename);      
    }

but it gives to me error:

File not found at path: C:/xampp/htdocs/tbg/storage/app/public/files

and URL: http://localhost/filess/download/8

Can someone help me? Thanks

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.