rikarsen's avatar

Multiple Image upload system

Hi. Who can send the image upload system examples for laravel 5, with validation.

0 likes
4 replies
bashy's avatar

Basic PHP here. Do a loop to read the images from $_FILES[''] and do validation on each.

bobbybouwmann's avatar

This is a really basic example but it should get you on your way ;)

$files = Input::file('images');

foreach ($files as $file) {
    // Validate each file
    $rules = array('file' => 'required'); // 'required|mimes:png,gif,jpeg,txt,pdf,doc'
    $validator = Validator::make(array('file'=> $file), $rules);

    if($validator->passes()) {
        $destinationPath = 'uploads';
        $filename = $file->getClientOriginalName(); 
        $upload_success = $file->move($destinationPath, $filename);

        // Flash a message and return the user back to a page...
    } else {
        // redirect back with errors.
        return Redirect::to('upload')->withInput()->withErrors($validator);
    }
}
1 like
bobbybouwmann's avatar

You can figure that out for yourself for sure ;) Give it a try and let us know what you tried and what isn't working

Please or to participate in this conversation.