【问题标题】:Get full path to file with Laravel Storage使用 Laravel Storage 获取文件的完整路径
【发布时间】:2019-02-09 08:34:52
【问题描述】:

我正在使用 Laravel 5.6 Storage API 将我的文件存储在 public/storage/images 中。这工作正常。当我想检索其中一个文件的完整 URL 时,我使用

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

返回

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

但由于我的服务器设置为忽略public,因此该地址不会返回图像。相反,这个地址:

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

返回图像。有没有办法使用 Laravel 的 API 生成这个地址,而不是做一个丑陋的查找和替换?

【问题讨论】:

  • 这是作品吗?将磁盘配置更改为 'url' => env('APP_URL').'../storage',
  • @kenken9999 关闭 - 我必须将其更改为 env('APP_URL').'/storage'。如果您将其添加为答案,我会将其标记为正确。

标签: php laravel


【解决方案1】:

在根目录中创建一个 .htaccess 文件并添加

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

【讨论】:

    【解决方案2】:

    尝试这一步到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
    

    现在在 url 中不公开地运行您的代码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-10
      • 1970-01-01
      • 1970-01-01
      • 2016-03-31
      • 2012-10-19
      • 2018-10-24
      相关资源
      最近更新 更多