CodeIgniter and File Upload Library
CodeIgniter is a compact and amazing framework for developing neat and clear PHP projects. The more I work in this, the more I’m falling in love with it. Though it’s very well documented, but you can’t expect to find all what you need in the help file.
I was working on a project where I do need to support the subtitle file upload (of type SRT and SUB). According to the documentation all I need to do to support this is add the following line:
$config['allowed_types'] = 'sub|srt';
But when I add this line, the CodeIgniter was reject the SRT and SUB files with error that file type upload is not supported. As the framework is open source, thank God, so I looked at the corresponding code, and found that during upload, the code also checks for the file mime types and reject the file if the corresponding mime type is not defined in the “/application/config/mimes.php”. Once I know this, fixing this was just a matter of minutes. All I did was added the following two lines to the $mimes array in the file and it worked flawless:
'srt' => array('text/plain', 'application/octet-stream'),
'sub' => array('text/plain', 'application/octet-stream'),
Tags: CodeIgniter, PHP, Upload
This entry was posted
on Sunday, August 15th, 2010 at 12:55 pm and is filed under PHP.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
Feedback & Comments
No Responses