Exarkun Exarkun - 3 years ago 293
PHP Question

Laravel validator and excel files error

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 problem at all but when i try with an excel files, the validator fail and say that not the good extension.

Here you can see my code, the two lines of comments was an other solution i have try , and it don't work too :(.

Any help is welcome.

public function postFile(Request $request)
{ //Règle de validation avec les type de fichiers acceptés

application/vnd.ms-excel, application/vnd.msexcel,
text/csv, text/anytext, text/plain, text/x-c,
/* 'extension' => strtolower($request->file->getClientOriginalExtension()),
if ($validator->fails()) {
return back()

Answer Source

Ok my fault. I had try an other solution find on this website and it work. Thanks for help Odin. It was my first question on this website i gonna see if i can help someone now. I poste code for solution in someone need :).

$validator = Validator::make(
      'file'      => $request->file,
      'extension' => strtolower($request->file->getClientOriginalExtension()),
      'file'          => 'required',
      'extension'      => 'required|in:doc,csv,xlsx,xls,docx,ppt,odt,ods,odp',


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download