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?

Share this article:
  • Twitter
  • Digg
  • StumbleUpon
  • Slashdot
  • Facebook
  • LinkedIn
  • email
  • Print