Reputation: 543
I'm trying to save images from the form input. But it's not working. I have code as following: View:
<form role="form" method="post" action="store" enctype="multipart/form-data">
<label class="control-label">Select Images</label>
<input id="image" name="image[]" multiple type="file">
Controller:
public function store(Request $request)
{
$image = $request->file('image');
$input['imagename'] = time().'.'.$image->getClientOriginalExtension();
$destinationPath = public_path('/images');
$image->move($destinationPath, $input['imagename']);
$this->postImage->add($input);
}
The $image in controller is returning nothing when i tried return($image). What is wrong in here? Can anyone help me?
Upvotes: 1
Views: 1592
Reputation: 31
can you change below code to
$image = $request->image('file');
and try.
Upvotes: 0
Reputation: 2076
You have array of images in <input id="image" name="image[]" multiple type="file">
. So you need to run foreach to get images from that array. If you want to upload single image please remove []
from image and write input like this:
<input id="image" name="image" type="file">
Upvotes: 1