Skip to content

Instantly share code, notes, and snippets.

@abdullah353
Created August 5, 2014 17:32
Show Gist options
  • Save abdullah353/a1b71d512467f0712818 to your computer and use it in GitHub Desktop.
Save abdullah353/a1b71d512467f0712818 to your computer and use it in GitHub Desktop.
Multiple file uploading in laravel From http://forumsarchive.laravel.io/viewtopic.php?id=11760
foreach(Input::file('file') as $file){
$rules = array(
'file' => 'required|mimes:png,gif,jpeg,txt,pdf,doc,rtf|max:20000'
);
$validator = \Validator::make(array('file'=> $file), $rules);
if($validator->passes()){
$ext = $file->guessClientExtension(); // (Based on mime type)
//$ext = $file->getClientOriginalExtension(); // (Based on filename)
$filename = $file->getClientOriginalName();
$file->move(public_path('upload'), $filename);
}else{
//Does not pass validation
$errors = $validator->errors();
}
}
Form::file('file[]', array('multiple'=>true));
//or:
<input multiple="1" name="file[]" type="file">
//Or for older browsers:
<input name="file[]" type="file">
<input name="file[]" type="file">
<input name="file[]" type="file">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment