Last post we wrote about how to extend the File Upload Library to set disallowed file types rather than only the allowed file types. We saw a fair amount of interest in file upload for CodeIgniter and have decided to post some tips for troubleshooting the most common issues we’ve come across.
“The filetype you are attempting to upload is not allowed”
Many times this is the appropriate error you would expect to see after a disallowed file type has been uploaded, however, we have noticed that there are a couple cases where files inaccurate fail. Here are some potential issues and their solutions.
- Option ‘allowed_types’ Is Required
If no list of file types is provided in $config['allowed_types'], you will always get this error. The documentation shows the options with a default value of “none”, but it fails to make it obvious that it is a required input. - MIME Type Is Not Listed
Another potential solution to this problem could be that the extension is not listed in config/mime.php. Any file type that should be allowed must exist in the $mime array or it will fail. - MIME Type Variations
Different browsers often return different MIME types. For this reason, config/mimes.php accepts multiple MIME types for a given file type. Many times a variant of the main MIME type will need to be added to accommodate all browsers.
$data['file_path'] is an Absolute Path
The $config array accepts ‘file_path’ as either a relative or absolute path. It is definitely convenient to allow either as an input, however, the $data array returned after processing the file returns an absolute path. This can certainly cause some issues if the expectation is that the returned ‘file_path’ is in the same format as the ‘file_path’ provided in the $config array.
Accepting Multiple Files in a Form
There is an ongoing discussion with code segments in the CodeIgniter Forums on how to accept multi-file uploads. There are a handful of great solutions available and lots of people supporting the topic.
What other issues have you come across with the File Upload Class in CodeIgniter? How do you see it being able to be improved or extended to be the most useful?








Comments
5 Comments
i have made code for upload but my problem is how to update the file i’ve already upload with form. i save the link of file to database.
One workaround to this BUG is to set the non-image filetypes in front of the allowed_types config setting. That way, you can use CI without patching it, because the non-image file types are checked first, before the image-check is done.
E.g.
In stead of setting this:
$config[‘allowed_types’] = ‘jpg|png|pdf|zip’;
You can use this:
$config[‘allowed_types’] = ‘pdf|zip|jpg|png’;
Thanks for the tip mzalazar, about changing the order of the allowed_types list, that’s very weird, but it now accepts my non-image formats for upload.
Solution is not hard like this.
go to system\libraries\upload.php
go to upload function and then find line 368-398 delete it out and then save
done.
after that u can upload all xxxx file u want
@Toto – I’m not sure which version you are using of CI, but those line numbers don’t work in CI 1.7.2. Also, it’s not recommended to modify core libraries since you would have to redo the fix if you upgrade to the next version of CI.