php 找不到 Laravel 5.4 存储文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43561700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.4 storage file not found
提问by Iftakharul Alam
I am using laravel 5.4. I upload some document file in storage/app/public/documents folder like
我正在使用 Laravel 5.4。我在 storage/app/public/documents 文件夹中上传了一些文档文件,例如
$request->paper_file->store('documents');
and my file uploaded successfully.
我的文件上传成功。
in file system default storage is public and public conf is like
在文件系统中,默认存储是公共的,公共 conf 就像
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',],
but when i hit /storage/documents/hQqlgifnVVH8bmrRPVdZ9aFGbhLmcc7g7bHZSX4u.pdf it says not found 404. How to solve this issue.
但是当我点击 /storage/documents/hQqlgifnVVH8bmrRPVdZ9aFGbhLmcc7g7bHZSX4u.pdf 时,它说没有找到 404。如何解决这个问题。
回答by Jebediah
By default Laravel puts files in the storage/app/public
directory, which is not accessible from the outside web. So you have to create a symbolic link between that directory and your public one:
默认情况下,Laravel 将文件放在storage/app/public
目录中,该目录不能从外部网络访问。因此,您必须在该目录和您的公共目录之间创建一个符号链接:
storage/app/public -> public/storage
storage/app/public -> public/storage
You can do that by executing the php artisan storage:link
command (docs).
您可以通过执行php artisan storage:link
命令 ( docs)来做到这一点。
回答by Franklin'j Gil'z
In laravel ^5.8:
在 Laravel ^5.8 中:
- Make sure you run the command
php artisan storage:link
to linkstorage/app/public
withpublic/storage
.
- 确保运行命令
php artisan storage:link
以链接storage/app/public
到public/storage
.
now:
现在:
// this return some like 'public/documents/file.ext'
$path = $request->paper_file->store('public/documents');
// this return some like 'storage/documents/file.ext'
$publicPath = \Storage::url( $path) );
// this return some like '< APP_URL env variable >/storage/documents/file.ext'
$url = asset( $publicPath );