Created
August 5, 2014 17:32
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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