Uploading videos using codeigniter is sometimes difficult for some people, because uploading videos need slightly different settings from other files such as .doc, .pdf, .txt. For example, we need to add support for mime which is needed for some video formats. So in this article, we will discuss how to upload a simple video with codeigniter.
Please follow the following steps in order.
- Make sure you have downloaded codeigniter and put it in the htdocs folder (../htdocs/ci-video).
- Create a folder to accommodate the uploaded files, name the folder with video in the root of your work folder. For example: htdocs/ci-video/video
- We need to add mime for files with .flv , .wmv, and .mp4 formats so that these video files can be uploaded with codeigniter. Therefore open the file mime.php which is in application/config/mimes.php.
Then add the following list:
‘wmv’ => array(‘video/wmv’, ‘video/x-ms-wmv’, ‘flv-application/octet-stream’, ‘application/octet-stream’),
‘mp4’ => ‘video/mp4’,
‘flv’ => array(‘video/flv’, ‘video/x-flv’, ‘flv-application/octet-stream’, ‘application/octet-stream’)
- Because usually the video format has a large file size, then we need to add the maximum size of the file that can be uploaded with php. For that we need to change the php.ini file, here I try to change the upload_max_filesize section to 32MB
upload_max_filesize = 32M
(the location of php.ini in each operating system is different)
Location on Xampp Windows: xampp/php/php.ini
Location on MAMP Mac : Application/MAMP/Conf/php5.x.x/php.ini
- Create a View with the name movie.php in (.. /Application/views/video/movie.php )