How to make CodeIgniter file upload class accept all extensions?


Question

Currently if I supply no extensions to the class it allows no extensions. I would like to allow all extensions. Is there any way to do this without hacking the core?

1
21
6/9/2009 5:24:31 PM

Accepted Answer

In Codeigniter 2, you simply need to define allowed types like this :

$config['allowed_types'] = '*';
62
5/4/2011 12:09:36 AM

What I do is:

$ext=preg_replace("/.*\.([^.]+)$/","\\1", $_FILES['userfile']['name']);
$fileType=$_FILES['userfile']['type'];
$config['allowed_types'] = $ext.'|'.$fileType;

That makes all files in every function call automatically allowed.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon