以下在5.5中正确上传/移动文件 - 能够从目录中查看/访问 - 但是Storage :: get不返回文件路径,即使创建了符号链接,直接访问文件也会给出404。
$currentuser_id = Auth::user()->id;
$file = request()->file('resume');
$fileName = $file->getClientOriginalName();
Storage::disk('uploads')->put($currentuser_id.'/'.$fileName, file_get_contents($file));
试图访问该文件,$ content结束为空:
$content = Storage::disk('uploads')->get($currentuser_id.'/filename.pdf');
直接访问文件会产生404:
https://www.website.com/storage/uploads/1/filename.pdf
Filesystems config:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
'uploads' => [
'driver' => 'local',
'root' => storage_path().'/uploads',
],
],
答案 0 :(得分:2)
您可以使用处理UploadedFile
提供的存储磁盘的方法来简化代码。
$file = request()->file('resume');
$file->storeAs(Auth::id(), $file->getClientOriginalName(), 'uploads');
Laravel 5.5 Docs - Requests - Storing Uploaded Files
storage/app/public
可能已关联,但storage/uploads
未链接到公共文件夹中,因此无法获取文件的可访问地址。