0

How to Access the Files in Storage.

File Location

storage/uploads/documentUpload/3_1620028799.PNG

Remember : php artisan storage link will not works because files are not in app/public folder.

File URL http://example.com/storage/uploads/logo/logo.png 404 error. is any way to overwrite in htaccess?

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
Fredericka Hartman
  • 835
  • 1
  • 7
  • 13
  • 1
    If it's not under `public` it is not accessible publically. It would be a security issue if it were. You can however do something like [this answer](https://stackoverflow.com/a/44131415/487813) and stream the file in Laravel code. this would also allow you to put the route behind middleware if you want to require authorisation for example – apokryfos May 03 '21 at 09:04

1 Answers1

3

You can create a new disk in your config/filesystems.php, for example uploads

'uploads' => [
    'driver'     => 'local',
    'root'       => storage_path('app/uploads'),
    'url'        => env('APP_URL') . '/storage/uploads',
    'visibility' => 'public',
],

and at the end of config/filesystems.php file, add a new symlink for uploads folder

'links' => [
    public_path('storage') => storage_path('app/public'),
    public_path('storage/uploads')  => storage_path('app/uploads'), // Add this
],

Then run php artisan storage:link

Whenever you want to get the url of file, just run

\Storage::disk('uploads')->url('documentUpload/3_1620028799.PNG');
SEYED BABAK ASHRAFI
  • 4,093
  • 4
  • 22
  • 32