我正在尝试将上传的文件移动到我的存储文件夹中。它实际上在图像文件中工作。但是,当我尝试上传pdf文件时,它在下面给了我一个错误。
错误
打开(D:\ document \ My Documents \ optodph \ public):无法打开流:权限被拒绝
查看
<form action="{{ route('upload.files') }}" method="POST" enctype="multipart/form-data">
@csrf
<input class="file-cpc" type="file" name="file" required>
</form>
在我的控制器中
$filename = auth()->user()->id;
$dir = '/users/',
Storage::disk('local')->putFileAs($dir, $request->file, $filename);
我出了什么问题吗?请帮助大家。
答案 0 :(得分:1)
尝试
$path = $request->file->store('users', 'local');
目录名称,'用户/ somepath','狗'等不需要分隔符
https://github.com/laravel/framework/blob/6.x/src/Illuminate/Filesystem/FilesystemAdapter.php#L233
routes / web.php
use Illuminate\Http\Request;
Route::get('upload/files', function (){
return view('index');
});
Route::post('upload/files', function (Request $request){
return $path = $request->file->store('/users/', 'local');
})->name('upload.files');
resources / views / index.blade.php
<form action="{{ route('upload.files') }}" method="POST" enctype="multipart/form-data">
@csrf
<input class="file-cpc" type="file" name="file" required>
<input type="submit" value="Submit">
</form>
url:your-domain.test / upload / files