0
votes

Can anyone tell me that how can I allow all the mime types which starts with video/ in Yii2.

currently my validations are like

[['attachmentfile'], 'file','skipOnEmpty'=>FALSE, 'extensions' => 'mp4,3gp,mov,m4v,mpeg,mpg', 'mimeTypes' => 'video/mp4,video/quicktime,video/x-quicktime,video/x-m4v,video/mov,video/3gpp,video/mpeg','on'=>  'create'],

now I want to allow each video because I am getting error in some videos uploading. So how can I allow all mime types which starts with video/*

Also please if anyone can tell me that is it a good approach?

Real problem- I have a video file which is mp4 and the mime type is video/mp4. When i upload it. My model generates error for mime type. For rest of my videos it is working fine till now. I tried to check mime type on a link online and it is also showing mp4. So I am not sure what is the problem with this video. I am using ffmpeg conversion now so I want to allow each video file to upload and will convert them to mp4. Only this video is creating problem. So if anyone can tell me how can I allow all the video/* mime types

1

1 Answers

2
votes

You could disable the mimeType checking with setting checkExtensionByMimeType to false

Yii2 Api: checkExtensionByMimeType

Other than that you have to add the MimeType your file is returning so that the check for it returns true.

Yii2 Api: basefilehelper::getMimeType

It could also be your problem that fileinfo doesn't return the correct mimeType. I also had this once on Windows were on Linux it was correct.

Stackoverflow: Fileinfo returns different mimetype on php version

Available MimeType Listings could be found here:

Stackoverflow: PHP / Mime Types - List of mime types publically available