Reputation: 290
Been trying tons of things to save a file upload into the proper directory in Laravel. I have the following in my controller. The $files and $folder variables are correct. The folder is being created properly but the file will not save to the folder:
$files = $request->file('current_plan_year_claims_data_file_1');
$folder = public_path(). "\storage\\$id";
if (!File::exists($folder)) {
File::makeDirectory($folder, 0775, true, true);
}
if (!empty($files)) {
foreach($files as $file) {
// Storage::disk('local')->put($file->getClientOriginalName(), file_get_contents($file));
Storage::disk(['drivers' => 'local', 'root' => $folder])->put($file->getClientOriginalName(), file_get_contents($file));
// Storage::put($file->getClientOriginalName(), $folder);
}
}
Upvotes: 0
Views: 157
Reputation: 775
you should try this code. error in your storage::disk
line. write driver instead of drivers.
$files = $request->file('current_plan_year_claims_data_file_1');
$folder = public_path(). "\storage\\$id";
if (!File::exists($folder)) {
File::makeDirectory($folder, 0775, true, true);
}
if (!empty($files)) {
foreach($files as $file) {
Storage::disk(['driver' => 'local', 'root' => $folder])->put($file->getClientOriginalName(), file_get_contents($file));
}
}
Upvotes: 1