Laravel validator and excel files error

后端 未结 7 1812
后悔当初
后悔当初 2020-12-09 12:31

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

7条回答
  •  醉酒成梦
    2020-12-09 13:09

    First tell that this is not the proper solution. But you can try this.

    I've searched also for that and having so much trouble validating excel file and their mimes type is not working for that unfortunately.

    if($request->hasFile('file'))
    {
       $extension = File::extension($request->file->getClientOriginalName());
       if ($extension == "xlsx" || $extension == "xls" || $extension == "csv") {
          //'Your file is a valid xls or csv file'
       }else {
          //'File is a '.$extension.' file.!! Please upload a valid xls/csv file..!!');
       }
    }
    

    in namspace include must use File;

    You can validate any file by this way, Thanks.

提交回复
热议问题