I want to upload multiple image files in database .. Here is the view part :
<input type="file" name="photo[]" >
<input type="file" name="photo[]" >
<input type="file" name="photo[]" >
And I want to store the path into different field in database..
controller code:
public function store(Request $request)
{
$product = new Product();
$product->name = $request->Input(['name']);
$product->description = $request->Input(['description']);
$files = Input::file('photo');
$names = [];
foreach ($files as $file) {
$names[] = $file->getClientOriginalExtension();
}
$imageName1 = time().'.'.$names[0];
$imageName2 = time().'.'.$names[1];
$imageName3 = time().'.'.$names[2];
$product->primary_image = $imageName1;
$file->move('images/', $imageName1);
$product->optional_image_one = $imageName2;
$file->move('images/', $imageName2);
$product->optional_image_two = $imageName3;
$file->move('images/', $imageName3);
$product->price = $request->Input(['price']);
$product->save();
return Redirect::to('product');
}
I got the following Error:
FileException in UploadedFile.php line 235: The file "3.jpg" was not uploaded due to an unknown error.
Can anyone what's the error for assigning into object? or solution please ..