I\'m new to Laravel. I have a form with a File upload function on it. How can I validate their file? I will only allowed Microsoft Word files. Here\'s my validation code.
To validate mime type of a file input in Laravel you can use the mimes
rule. Remember to match the mime type detected with the actual mime of file you provide. It may vary on different servers.
For example, you want to enable adding and word document in you form:
1) in config/mimes.php
add the below mime types:
'doc' => array('application/msword', 'application/vnd.ms-office'),
'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip'),
2) in your validation $rules
add the following elements:
'file' => 'required|max:10000|mimes:doc,docx' //a required, max 10000kb, doc or docx file
Try this?
'file' => 'required|max:10000|mimes:application/vnd.openxmlformats-officedocument.wordprocessingml.document'
You may want to set some custom message for the response though :)