我想将数据(文件)的存储路径从默认的storage/app/public
更改为public/files.
控制器
public function store(Request $request)
{
request()->validate([
'filename' => 'required',
]);
$files = $request->file('filename');
foreach ($files as $file) {
File::create([
'filename' => $file->getClientOriginalName(),
]);
}
return redirect('/file')->with('success', 'File Uploaded Successfully');
}
答案 0 :(得分:0)
转到配置文件夹-> filesystems.php
'public' => [
'driver' => 'local',
'root' => public_path(),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
public function upload(Request $request)
{
$uploadedFile = $request->file('filename');
$filename = time().$uploadedFile->getClientOriginalName();
Storage::disk('local')->putFileAs(
'files/'.$filename,
$uploadedFile,
$filename
);
$upload = new Upload;
$upload->filename = $filename;
$upload->save();
}
答案 1 :(得分:0)
>>
答案 2 :(得分:0)
在您的config / config / filesystems.php中,您可以像这样:
'disks' => [
'uploads' => [
'driver' => 'local',
'root' => public_path() . '/uploads',
'url' => env('APP_URL').'/public',
'visibility' => 'public',
],
]
然后像这样存储:
Storage::disk('uploads')->put('filename', $file_content);