I have an input field who allaow peoples to upload files. I want that they can upload, word files like doc, and files like csv,xlsx.
When i try with a .doc no proble
In Laravel you can use validate the file upload with extension using After Hooks. Read more from here!
$validator->after(function ($validator) use ($request){
if($this->checkExcelFile($request->file('file')->getClientOriginalExtension()) == false) {
//return validator with error by file input name
$validator->errors()->add('file', 'The file must be a file of type: csv, xlsx, xls');
}
});
function checkExcelFile($file_ext){
$valid=array(
'csv','xls','xlsx' // add your extensions here.
);
return in_array($file_ext,$valid) ? true : false;
}