简体   繁体   中英

Get full path to file with Laravel Storage

I am using the Laravel 5.6 Storage API to store my files in public/storage/images . This works fine. When I want to retrieve a full URL for one of these files, I use

$path = Storage::disk('public')->url('images/' . $url);

This returns

http://localhost:1234/public/storage/images/foobar.jpg

But since my server is set up to ignore public , this address does not return the image. Instead, this address:

http://localhost:1234/storage/images/foobar.jpg

returns the image. Is there any way to produce this address using Laravel's API, rather than doing an ugly find & replace?

try this step to ignore public in path

1)Rename `service.php` to `index.php` in your root drive
2)copy `.htaccess` file from public folder and paste into root drive

now run your code without public in url

create a .htaccess file in root directory and just add

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ public/index.php/$1 [L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM