I got some errors with the following code, I searched a lot but I didn't get the solution. I want to upload file.xls, am I wrong? Thanks
My HTML Form:
<form class="form-horizontal" role="form" method="post" action="{{ URL::to('doc/test') }}" enctype="multipart/form-data">
<input style='width:400px;' type='file' id='files' name='files[]' class="form-control" multiple='multiple'>
<button type="submit" class="btn btn-primary">Save</button>
</form>
My Controller Function
public function uploadDocs()
{
$files = Input::file('files');
$errors = "";
foreach($files as $file)
{
$rules = array('file' => 'mimes:png,gif,jpeg,pdf,doc,docx,xls,xlsx,max:1000000'); //'required|mimes:png,gif,jpeg,txt,pdf,doc'
$validator = Validator::make(array('file'=> $file), $rules);
if($validator->passes())
{
$destinationPath = 'documents';
$filename = $file->getClientOriginalName();
$temp = explode(".", $filename);
$extension = end($temp);
$filename = $temp[0].'_'.date('Y-m-d H:i:s').$extension;
$upload_success = $file->move($destinationPath, $filename);
}
else
{
return Redirect::back()->withErrors($validator);
}
}
}
Errors:
The file must be a file of type: png, gif, jpeg, pdf, doc, docx, xls, xlsx, max:1000000.