umefarooq's avatar

excel file upload validation mime type error.

Hi i am trying to upload excel file i am also validating excel file but facing problem with excel file mime type validation here is code i am using for file

'file' => 'required|mimes:xls,xlsx'

i don't know how laravel is checking mime, where i can set missing mimes for excel files in laravel.

0 likes
5 replies
d3xt3r's avatar

From the 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. A full listing of MIME types and their corresponding extensions may be found at the following location: http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types

Also, may be this could help https://laracasts.com/discuss/channels/general-discussion/custom-validation-for-xlxs-and-xls

umefarooq's avatar

it dose not worked for me, i created custom rule to check only excel file. i think there is some problem with mime validation rule or I'm doing something wrong, i have tried txt mime it is not validating txt file.

kingpabel's avatar

you need to do some changes,see this

'file' => 'required|mimes:application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
shivactp's avatar

This is also not working for excel validation

1 like
MultCompiler's avatar

I tried validators provided by laravel but all doesnt seems to work.. That gave me an idea to try to validate using normal php and it works like a cham

    $extensions = array("xls","xlsx","xlm","xla","xlc","xlt","xlw");

    $result = array($request->file('import_file')->getClientOriginalExtension());

    if(in_array($result[0],$extensions)){
         // Do something when Succeeded 
    }else{
       // Do something when it fails
    }
1 like

Please or to participate in this conversation.