laravel 5.1 error in validating doc docx type file

22,484

Solution 1

thanks solved it by allowing zip

$validator = Validator::make($request->all(), [
            'resume'   => 'mimes:doc,pdf,docx,zip'
        ]);

this is because https://en.wikipedia.org/wiki/Office_Open_XML

Solution 2

In Laravel 5.6.3., I have solved this using dot(.) sign:

$request->validate([
    'file.*' => 'required|file|max:5000|mimes:pdf,docx,doc',
]);
Share:
22,484

Related videos on Youtube

sanu
Author by

sanu

Updated on July 10, 2021

Comments

  • sanu
    sanu almost 3 years

    Hi i am facing a docx type validation problem. I tried

    $validator = Validator::make($request->all(), [
                'resume'   => 'mimes:doc,pdf,docx'
            ]);
    

    It will upload pdf file with no error but whenever i try to upload docx files it gives validation error 'must be a file of type: doc, pdf, docx'
    any idea

    • shock_gone_wild
      shock_gone_wild over 8 years
      What ist your result if you do a dd($request->file('resume')->getMimeType());
    • sanu
      sanu over 8 years
      it shows "application/zip surprised
  • Dave Carruthers
    Dave Carruthers almost 5 years
    As far as I can tell this allows fake files to pass validation. for example, renaming a .txt file to .pdf passes the validation, remove the dot * and it fails as expected.