【问题标题】:Laravel Storage File not found未找到 Laravel 存储文件
【发布时间】:2021-02-12 00:12:24
【问题描述】:

我正在尝试将可下载的 csv 模板绑定到一个按钮,该按钮将位于存储中,但我一直收到我在下面尝试过的错误,但没有运气,谁能看到我哪里出错了?

下载路线

创建了一个引用存储中模板的下载路径。

public function download()
{
   return Storage::download('template.csv');
}

路由文件

Route::get('invites/download', 'InviteController@download')->name('invite.download');

按钮

<a href="{{action('InviteController@download')}}" class="btn btn-primary mb-3">Download template</a>

模板位置

storage/app/public/template.csv

错误

这是我不断收到的错误。

League \ Flysystem \ FileNotFoundException
File not found at path: template.csv

我可以得到一些帮助,看看我哪里出错了吗?

【问题讨论】:

    标签: laravel laravel-storage


    【解决方案1】:

    您可以通过简单地使用 file_get_contents() 来解决此问题:

    return file_get_contents(public_path('storage/template.csv'));
    

    如果您也创建了符号链接php artisan storage:link,这将起作用,

    如果你想使用storage_path,那么:

    return file_get_contents(storage_path('app/public/'.'template.csv'));
    

    【讨论】:

      猜你喜欢
      • 2017-09-19
      • 2022-01-15
      • 1970-01-01
      • 2020-01-21
      • 2017-07-27
      • 1970-01-01
      • 2020-10-11
      • 2018-11-25
      • 2016-08-27
      相关资源
      最近更新 更多