php - Multiple Image Upload in Laravel 5.2 -
finally can upload , move images, want create multiple upload images on laravel. possible? did have use array make it?
can modify little bit code?
it's on productcontroller.php
$picture = ''; if ($request->hasfile('images')) { $file = $request->file('images'); $filename = $file->getclientoriginalname(); $extension = $file->getclientoriginalextension(); $picture = date('his').$filename; $destinationpath = base_path() . '\public\images/'; $request->file('images')->move($destinationpath, $picture); } if (!empty($product['images'])) { $product['images'] = $picture; } else { unset($product['images']); }
thank you. note: code above kindhearted person on stackoverflow, again ;)
at frontend form you'll have use field attribute name
name="images[]"
and controller code this.
$picture = ''; if ($request->hasfile('images')) { $files = $request->file('images'); foreach($files $file){ $filename = $file->getclientoriginalname(); $extension = $file->getclientoriginalextension(); $picture = date('his').$filename; $destinationpath = base_path() . '\public\images'; $file->move($destinationpath, $picture); } } if (!empty($product['images'])) { $product['images'] = $picture; } else { unset($product['images']); }
Comments
Post a Comment