coolpraz's avatar

cant validate otf format

i made a form to upload fonts on server and i put validation rule only accept file with .ttf and .otf extension and its working with .ttf format but when i upload .otf extension file format the validation fails.

$this->validate($request, [
            'title' => 'required',
            'font_file' => 'required|mimes:ttf,otf'
        ]);

I'm using Laravel 5.3 and php 7

the validation error is

The font file must be a file of type: ttf, otf.
0 likes
4 replies
tonytran's avatar

Its not working and have tried below combination but no success

application/x-font-otf,

font/opentype,

opentype,

otf

please help me to sorted this out.

1 like
LiamMcArthur's avatar

@tonytran did you ever find a solution for this? I've tried adding 'opentype' and 'font/opentype' into my allowed-types - but it's still not working.

Naren's avatar

''' $this->validate($request, [ 'title' => 'required', 'font_file' => [ 'required', function($attribute, $value, $fail) { $fileInfo = new \Finfo(FILEINFO_MIME_TYPE); $mimeType = $fileInfo->file($value); $validType = array('application/vnd.ms-opentype','application/font-sfnt','application/vnd.ms-fontobject'); if(!in_array($mimeType, $validType)){ return $fail($attribute.' must be a file of type ttf, otf.'); } }, ], ]); '''

Please or to participate in this conversation.