CodeIgniter Forums
all mime types to upload - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: all mime types to upload (/showthread.php?tid=4329)



all mime types to upload - El Forum - 11-18-2007

[eluser]Unknown[/eluser]
Hi All,
i have question on upload file class.
here we can set the mime types we want to upload :$config['allowed_types']='gif|jpg|png|';
what if i want to upload all the mime types?should i write them the in $config['allowed_types']?or there is a way to tell all the types!!!

Thanks.


all mime types to upload - El Forum - 11-18-2007

[eluser]Derek Allard[/eluser]
I can't think of any built in preference to allow this - are you sure that you want to allow any possible file? Executables, viruses, etc? The CI mime type detection isn't perfect, but its a very large step in the right direction.

That said, if you've already authenticated users or something, then here's how you can do it. Create a copy of the file called Upload.php (in the libraries folder) and save it in application/libraries (you may need to create this folder).

Look through it, and find the function is_allowed_filetype() and replace it with this

Code:
function is_allowed_filetype()
{
return TRUE;
}

I haven't tested, but what should happen is that CI will preferentially use your library, and your library always says the file is good. Hope this is helpful.


all mime types to upload - El Forum - 11-18-2007

[eluser]Michael Wales[/eluser]
coolfactor posted a nice piece of code over in another thread

Code:
class MY_Upload extends CI_Upload {

    function is_allowed_filetype()
    {
        return (!$this->allowed_types ? TRUE : parent::is_allowed_filetype());
    }

}

This allows you to not entirely ditch the filetype permissions. If you do define allowed filetypes it will use those, if not - anything is allowed.


all mime types to upload - El Forum - 11-18-2007

[eluser]xwero[/eluser]
In the mimes config file you could do something like
Code:
$mimes = array(
// ...
'img' => array('application/postscript','image/bmp','image/gif','image/jpeg'),
// ...
);
You can add all the image types. The same you could do for video, webfiles and all.

No hacks needed, you have to learn to love config files Smile


all mime types to upload - El Forum - 11-19-2007

[eluser]xwero[/eluser]
Oops i was wrong thinking it would be possible to add img to the mimes and it would all work out, i'm sorry.