[英]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
.我正在使用 Laravel 5.6 Storage API 将我的文件
public/storage/images
在public/storage/images
。 This works fine.这工作正常。 When I want to retrieve a full URL for one of these files, I use
当我想检索这些文件之一的完整 URL 时,我使用
$path = Storage::disk('public')->url('images/' . $url);
This returns这返回
http://localhost:1234/public/storage/images/foobar.jpg
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.但是由于我的服务器设置为忽略
public
,因此该地址不会返回图像。 Instead, this address:相反,这个地址:
http://localhost:1234/storage/images/foobar.jpg
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?
有没有办法使用 Laravel 的 API 生成这个地址,而不是进行丑陋的查找和替换?
try this step to ignore public
in path尝试此步骤以
ignore public
路径中的ignore public
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现在在 url 中不公开地运行您的代码
create a .htaccess file in root directory and just add在根目录中创建一个 .htaccess 文件并添加
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ public/index.php/$1 [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.