Welcome Guest, Not a member yet? Register   Sign In
all mime types to upload
#1

[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.
#2

[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.
#3

[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.
#4

[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
#5

[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.




Theme © iAndrew 2016 - Forum software by © MyBB