Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel validation pdf mime

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"
     ....
       ]
like image 801
alex Avatar asked Feb 29 '16 08:02

alex


1 Answers

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"
]
like image 55
Froxz Avatar answered Nov 16 '22 22:11

Froxz