20CodeIgniter uploads, allow any filetype

CodeIgniter uploads, allow any filetype

CodeIgniter, the brilliant PHP framework currently does not allow you to just upload any filetype using the built in upload library. Although it’s generally a bad idea to allow your users to upload any types of file there may be the occassional need to do exactly this.

The way CodeIgniter currently does it is by making you list all of the filetypes which you’d like to let the user upload. Unless you want to sit there for a while typing a very long list why not do this simple trick. This is only a temporary fix and isn’t ideal as it does involve editing the CodeIgniter libraries but it does work. This will allow you to upload any type of file using the upload library.

Simply open up ‘system/libraries/Upload.php’ and do a search for ‘function is_allowed_filetype’. That should take you to the function used to determine whether or not the file upload should be accepted.

Now all you have to do is put ‘return true’ inside that function, right at the top. You should now be able to upload literally any type of file. Be careful though! As I said just a second ago this is generally a bad idea and can open up some very serious security holes!

Codeigniter Tutorials

Codeigniter Tutorials

I don’t know that codeigniter doesn’t allow some extensions to be uploaded. I thought all file are able to be uploaded

Michael Morgan

Michael Morgan

Nope, from what I’ve seen there is no ‘allow-all’ for the CodeIgniter file upload class.