Ayyaz Zafar
Ayyaz Zafar

Reputation: 2163

Codeigniter: MP4 Video Upload not working

I am researching on a problem for long time but still could not find any solution.

I am uploading mp4 file using codeigniter. Before that I added mime type for mp4 in config/mimes.php. I tried both: mp4 => video/mp4 and mp4 => array('video/mp4', 'video/3gpp')

Both of these works perfect in Local server but whenever I test this on the Live server then It always give the same error message "The filetype you are attempting to upload is not allowed.".

I tried one more thing. i.e. $config['allowed_types'] = "*";

It works perfect in both local and online server.

But I want just mp4 video type.

Anybody have some solution for this strange problem?

Upvotes: 4

Views: 13850

Answers (4)

Mahadi  Hassan Babu
Mahadi Hassan Babu

Reputation: 521

  • I think you did everything but not getting ultimately output. You may follow the the below instruction that's solved my problem.
  • Open your php.ini file using sudo gedit /etc/php/<PHP_VERSION>/apache2/php.ini for linux or go to your php.ini file.
  • change upload_max_filesize = 2M to upload_max_filesize = 100M or as your choice.
  • change post_max_size = 2M to post_max_size = 100M or as your choice like as 200M or 500M
  • Now restart your apache using sudo systemctl reload apache2 command or if you not a linux user (using Xampp or Laragon just stop your machine and restart again)
  • It has solved my problem, hope it will also help you.

Upvotes: 0

Ajay Patidar
Ajay Patidar

Reputation: 314

I depend on video mime file types when we upload video with extension mp4 but in CodeIgniter upload library use php function finfo_file for detect file_type by this function we get other file_type. Ex. I get video/3gpp

So I changed in config/mimes.php

'mp4' => array('video/mp4', 'video/3gpp'),

and its working for me.

Thanks

Upvotes: 0

Ayyaz Zafar
Ayyaz Zafar

Reputation: 2163

Finally I got solution of my Problem so I am writing this answer.

Mostly detection of mime types in local and online server are different.

In my case, Local server was getting file_type as "video/mp4". But online server was detecting the mime type as 'application/octet-stream'.

So I added both in array in the mime type list in my config folder:

'mp4' => array('video/mp4', 'application/octet-stream'),

Now it works perfectly in both local and online server.

Upvotes: 8

Mehta Harshit
Mehta Harshit

Reputation: 140

If everything doesn't work, rearrange the allowed type order like this, placing the video format first:

$config['allowed_types'] = 'mp4|jpg|png|'

It works in my case.

Upvotes: 1

Related Questions