Welcome Guest, Not a member yet? Register   Sign In
Overwrite one function in download class.
#1

[eluser]businessman332211[/eluser]
I just want to overwrite ONE function in the uploader class.
I have created a new file inside applications/library and it's
My_Upload.php.
I have added the following code to it:
I basically want to overwrite the original filetype check function and add that
ability to use * as a wildcard. For some reason when I do this however it's
not overwriting the function.
Any advice?
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Upload extends CI_Upload{
    
    function My_Upload($props = array())
    {
        parent::CI_Upload($props);
    }
    
    /**
     * Verify that the filetype is allowed
     *
     * @access    public
     * @return    bool
     */    
     /*
     Adjustments: I have overwritten the original is_allowed_filetype
     function with the same function.  The only modification is it adds
     a feature to allow the * to be used for filetypes in order to bypass
     the check.
     */
    function is_allowed_filetype()
    {
        if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types))
        {
            $this->set_error('upload_no_file_types');
            return FALSE;
        }

        // This was added.  If the * is passed as a wildcard it bypasses this filetype check.
        if ($this->allowed_types[0] == '*') return TRUE;

        $image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe');

        foreach ($this->allowed_types as $val)
        {
            $mime = $this->mimes_types(strtolower($val));

            // Images get some additional checks
            if (in_array($val, $image_types))
            {
                if (getimagesize($this->file_temp) === FALSE)
                {
                    return FALSE;
                }
            }

            if (is_array($mime))
            {
                if (in_array($this->file_type, $mime, TRUE))
                {
                    return TRUE;
                }
            }
            else
            {
                if ($mime == $this->file_type)
                {
                    return TRUE;
                }    
            }        
        }
        
        return FALSE;
    }
    
    // --------------------------------------------------------------------
}
?>
#2

[eluser]Flemming[/eluser]
it needs to be name MY_Upload ... not My_Upload!
#3

[eluser]businessman332211[/eluser]
Perfect. Finally working. Thanks for that.




Theme © iAndrew 2016 - Forum software by © MyBB