Home > Software engineering >  download file from the storage in laravel
download file from the storage in laravel

Time:03-26

i have laravel app, and i have a problem to make a storage link in the Hostinger, i tried everything and still not working,, so now I nedd to download files directly from (storage) in my rool laravel path not in public folder, how can I do that, I tried this code:

 @if(is_file(storage_path('app'). '/public/user_files/files/' . $user->files))
                    <strong> <a href="{{ 'storage/app/public/user_files/files/'.$user->files }}">Download</a></strong>

for the code above i have accessed the files in the storage, but I couldn't download it, show me this error:

404 not found

CodePudding user response:

@if(is_file(storage_path('app'). '/public/storage/user_files/files/' . $user->files))
<strong> <a href="{{ asset('storage/user_files/files/'. $user->files) }}">Download</a></strong>

CodePudding user response:

1st you can run this command

php artisan storage:link

you can use this path inside the assest()

@if(is_file(storage_path('app'). '/public/storage/user_files/files/' . $user->files))
<strong> <a href="{{ asset('storage/app/public/user_files/files/'. $user->files) }}">Download</a></strong>
  • Related