Laravel 5.6 存储::未找到下载文件

dar*_*jus 2 php storage download laravel

我使用的是 Laravel 5.6,filesystems.php 配置默认。

当文件上传时,我在我的数据库中记录了路径列,其中记录的路径如 - posts/p4NbvgcxHFcT10TwbS2UUJrajifPcqpN3i7iSyyk.png

创建了符号链接并将文件存储在公共目录中。

 $path = $file->store('posts', 'public');
Run Code Online (Sandbox Code Playgroud)

这个路径是记录器到数据库,如果我想显示例如图像,我可以通过以下方式访问它:

{{ asset('/storage/'.$file->path) }}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试强制下载它时会出现异常 - FileNotFoundException File not found at path:

文件下载方法:

  public function downloadFile($id){
    $file = File::find($id);

    //return Storage::download(storage_path()."/app/public/".$file->path, $file->original_name);
    //also tried like this
    return Storage::download(asset('storage/'.$file->path), $file->original_name);
}
Run Code Online (Sandbox Code Playgroud)

在 Windows 操作系统上运行的应用程序

dar*_*jus 11

解决方案是: return Storage::disk('public')->download($file->path);