uppermost
uppermost

Reputation: 185

Get image as an object

Uploading image from single upload form works fine. Code that i use:

View:

<input type="file" name="image" class="form-control">

Controller

$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:

View:

<input type="file" name="quiz[777][image]" class="form-control">

Controller [ problem ]

$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

Answers (2)

FULL STACK DEV
FULL STACK DEV

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

Sohel0415
Sohel0415

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

Related Questions