Reputation: 320
I tried it but it was an error
Cannot use object of type Illuminate\Http\UploadedFile as array
Does anyone have a solution for this ???
Hope someone could help, best regards :)
controller
public function store(Request $request)
{
foreach ($request->file_name as $key => $value) {
$freedownloadfiles = new FreeDownloadFiles();
$extension = $request->file('file_upload')->getClientOriginalExtension();
$freedownloadfiles->files = Storage::disk('yourstitchart')->putFileAs('',
$request->file_upload[$key], $extension);
$freedownloadfiles->file_name = $value;
$freedownloadfiles->free_download_id = $freedownload->id;
$freedownloadfiles->save();
}
return redirect()->route('freedownload');
}
Upvotes: 0
Views: 1879
Reputation: 57
Are you sure you get you'r data from ($key => $value) ? i see you get extension from request and you didn't convert it to the parsed data. When you foreach on array you access to any element it contain . You must access that element with $value !
Send files with html code like :
<input type="file" name="filenames[]" >
Get as following :
if($request->hasfile('filenames'))
{
foreach($request->file('filenames') as $file)
{
$name = time().'.'.$file->extension();
//write here what do you want
}
}
And you can see this answer: Cannot use object of type Illuminate\Http\UploadedFile as array
Upvotes: 1