Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

akhmami's avatar

Laravel validation error, while upload excel file

I took an excel file from google spreadsheets and downloaded it to excel. When I upload it, I get an error message The upload must be a file of type: xlsx, csv., but if I take it directly from the ms.excel application, it works fine. this is my code

protected $rules = [
        'type' => 'required|in:psb,mutasi',
        'upload' => 'required|file|mimes:xlsx,csv',
    ];
0 likes
6 replies
akhmami's avatar

@newbie360 i checked the mime type and it was application/octet-stream, and i changed my rules to this

protected $rules = [
        'type' => 'required|in:psb,mutasi',
        'upload' => 'required|file|mimetypes:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,application/octet-stream',
];

and it's still same error.

drgreen's avatar

@akhmami What is the file size that you were trying to upload? You may also want to check your php.ini configuration on this part:

post_max_size = 20M 
upload_max_filesize = 20M
akhmami's avatar
akhmami
OP
Best Answer
Level 1

@newbie360 it's application/vnd.openxmlformats-officedocument.spreadsheetml.sheetapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet. thanks, you saved my day.

protected $rules = [
        'type' => 'required|in:psb,mutasi',
        'upload' => 'required|file|mimetypes:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheetapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
];

it works fine.

Please or to participate in this conversation.