Laravel validation pdf mime

amin picture amin · Feb 29, 2016 · Viewed 33.6k times · Source

I have tried below mime types for validating PDF files.but none of them doesnt pass the validation .

  $rules  = [
     ....
    "file" => "required|mimes:application/pdf, application/x-pdf,application/acrobat, applications/vnd.pdf, text/pdf, text/x-pdf|max:10000"
     ....
       ]

Answer

Froxz picture Froxz · Feb 29, 2016

Just add file extension

$rules  = [
    "file" => "required|mimes:pdf|max:10000"
]

From laravel Docs:

Even though you only need to specify the extensions, this rule actually validates against the MIME type of the file by reading the file's contents and guessing its MIME type.


Update:

Starting from Laravel 5.2, you could validate file upload against full MIME type, new validation rule called: mimetypes.

$rules  = [
    "file" => "required|mimetypes:application/pdf|max:10000"
]