Feel It
Feel It

Reputation: 31

Can't access to file from storage path in laravel 5.8

I have some trouble while triying to acces file from storage path. So, i have already done php artisan storage:link. File access are fine in local using these method asset('storage/file.xx'), url('storage/file.xx') or 'storage/file.xx'. But i can't access file with these method on shared hosting and got 404 error for file link. Any idea? Can help? Thanks

Upvotes: 0

Views: 4032

Answers (3)

engrhussainahmad
engrhussainahmad

Reputation: 1134

We can't access storage directory in Laravel directly so we need to make symlink, which will create a short link inside public directory pointing to storage one. This way we are using the files and change as we need. If we want to change the default upload directory then we have to replace storage_path() inside filesystems.php with public_path(). Then we will be able to access and manipulate the files easily.

Upvotes: 0

Niket Joshi
Niket Joshi

Reputation: 748

  • Store files in public folder then retreive them on view. for that you have setting up disk on config/filesystems.php

     'uploads' => [
      'driver' => 'local',
      'root'   => public_path(),
    ],
    

Then call the disk while saving file.

Thank you, I hope this will helps you.

Upvotes: 0

Feel It
Feel It

Reputation: 31

To solve the problem finally, I have set a disk on config/filesystems.php as below.

'uploads' => [
   'driver' => 'local',
   'root'   => public_path(),
],

Then in controller, I save file like:

$request->file->storeAs($path, $name, 'uploads');

Upvotes: 3

Related Questions