Reputation: 185
Uploading image from single upload form works fine. Code that i use:
<input type="file" name="image" class="form-control">
$input['image'] = time().'.'.$request->image->getClientOriginalExtension();
$request->image->move(public_path('images'), $input['image']);
Gallery::create($input);
return back()->with('success','Image Uploaded successfully.');
But i need to change previous view so images will belong to array with specific key:
<input type="file" name="quiz[777][image]" class="form-control">
$input['image'] = time().'.'.Input::get('quiz')[777]['image'])->getClientOriginalExtension();
Input::get('quiz')[777]['image'])->move(public_path('images'), $input['image']);
Gallery::create($input);
return back()->with('success','Image Uploaded successfully.');
In controller now i am getting errors, that image is not an object and so i cant use getClientOriginalExtension() and move methods.
I also tried $request->Input::get('quiz')[777]['image'])
but without success.
Upvotes: 1
Views: 1427
Reputation: 15971
Rather than using Input::get()
use Input::file();
So change this
Input::get('quiz')[777]['image'])->getClientOriginalExtension();
Input::get('quiz')[777]['image'])->move(public_path('images'), $input['image']);
to this
request()->file('quiz')[777]['image'])->getClientOriginalExtension();
request()->file('quiz')[777]['image'])->move(public_path('images'), $input['image']);
Upvotes: 1
Reputation: 9873
Use Input::file()
to get uploaded file
$input['image'] = time().'.'.Input::file('quiz')[777]['image'])->getClientOriginalExtension();
Input::file('quiz')[777]['image'])->move(public_path('images'), $input['image']);
Upvotes: 3