views:

2423

answers:

4

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  A: 

So far it looks like it would only be possible via a hack.

I inserted a return true on line 556 in system/libraries/Upload.php.

Click Upvote
I prefer making a custom library over editing the system/libraries/ folder. Updating to a new version on CI usually means replacing the old system/ folder (except system/application/) with the latest version. CMIIW
andyk
+4  A: 

The answer to your direct question: No, there's no way to do this without overriding the core

To good news is you can avoid hacking the core, per the manual

As an added bonus, CodeIgniter permits your libraries to extend native classes if you simply need to add some functionality to an existing library. Or you can even replace native libraries just by placing identically named versions in your application/libraries folder.

So, to have a drop in replacement for your library, you could copy Upload.php to your

application/libraries

folder, and then add your custom logic to that Upload.php file. Code Igniter will include this file instead whenever you load the upload library.

Alternately, you could create your OWN custom uploader class that extends the original, and only refines the is_allowed_filetype function.

application/libraries/Myuploader.php
class Myuploader Extends Uploader{
    function is_allowed_filetype(){
         //my custom code here
    }
}

You'll want to read over the changelog whenever you're upgrading, but this will allow you to keep your code and the core code in separate universes.

Alan Storm
How's magento coding going Alan?
Click Upvote
+1  A: 

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.

Adam
Well that's just silly! :-)
Phil Sturgeon
A: 

You simply need to replace this condition:

        if (! $this->is_allowed_filetype())
        {
            $this->set_error('upload_invalid_filetype');
            return false;
        }

With:

        if (count($this->allowed_types) && !$this->is_allowed_filetype())
        {
            $this->set_error('upload_invalid_filetype');
            return false;
        }
Sarfraz