sanu
sanu

Reputation: 1068

laravel 5.1 error in validating doc docx type file

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

Upvotes: 7

Views: 26496

Answers (3)

Maduka Jayalath
Maduka Jayalath

Reputation: 1703

For Laravel 7+ to validate doc, docx you need to create mimes.php in config directory and add the following content,

config/mimes.php

<?php
 
return [
    'doc'  => array('application/msword', 'application/vnd.ms-office'),
    'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip'),
];

Upvotes: 0

Bedram Tamang
Bedram Tamang

Reputation: 4365

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

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

Upvotes: 10

sanu
sanu

Reputation: 1068

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

Upvotes: 25

Related Questions