0

I want to create a hyperlink to download a file in my storage/app/public folder. I am using this in the blade

<a href="{{ asset('storage/app/public/1489082996.docx') }}" download="{{ asset('storage/app/public/1489082996.docx') }}"> Read Paper</a>

But this show me the error file not found.What should i do do this is my filesystem.php

'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'visibility' => 'public',
        ],
Mutasim Fuad
  • 606
  • 2
  • 12
  • 31

2 Answers2

3

An easy way that allow you to store your files in the storage folder and allow to download without system changes: (in laravel 5.3)

You can make a normal link to the file:

<a href="/download/1489082996.docx"> Read Paper</a>

Then you need to configure your routes/web.php

Route::get('/download/{file}', function ($file='') {
    return response()->download(storage_path('app/public/'.$file)); 
});

This should open the download dialog for all the kinds of files, also for img's and pdf's. If you want to show the files online and not to download you should use the file method:

return response()->file(storage_path('app/public/'.$file));
rebduvid
  • 1,104
  • 10
  • 13
0

Asset paths are relative to the /public directory. So you would just want asset('1489082996.docx') assuming you've properly sym linked your storage directory with php artisan storage:link.

Jeff
  • 24,623
  • 4
  • 69
  • 78