Welcome Guest, Not a member yet? Register   Sign In
Problem Extending Library
#1

[eluser]Xiphar[/eluser]
Hi
I want to extend the Upload library.
I created a file Upload.php and put the file in the application/libraries folder.
This is how my class file look likes:

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class MY_Upload extends CI_Upload {
    
    function __construct($props = array()) {
        parent::CI_Upload($props);
    }
    
    //overwrite parent function to check if a file is actually ann image
    //and not simply a renamed exe/script
    function is_allowed_filetype()
    {
        if (count($this->allowed_types) == 0)
        {
            $this->set_error('upload_no_file_types');
            return FALSE;
        }
        
        //--- ADDED BY ME
        if($this->is_image())
        {
            $D = @getimagesize($this->file_temp);
            if($D['0'] === '')
            {
                return FALSE;
            }
        }
        //--- END OF ADDITION
        
        foreach ($this->allowed_types as $val)
        {
            $mime = $this->mimes_types(strtolower($val));
        
            if (is_array($mime))
            {
                if (in_array($this->file_type, $mime, TRUE))
                {
                    return TRUE;
                }
            }
            else
            {
                if ($mime == $this->file_type)
                {
                    return TRUE;
                }    
            }        
        }
        
        return FALSE;
    }
}
?>

The problem is that when I am calling the upload library, I am getting the following error:

Fatal error: Class 'CI_Upload' not found in path\to\system\application\libraries\Upload.php on line 2

Any idea why? My config file has the subclass prefix set to 'MY_'.

Your help would be greatly appreciated. Right now I am getting around by making changes to the original library which I do not like.

Thanks

Xiphar
#2

[eluser]tonanbarbarian[/eluser]
The filename for your file should be My_Upload.php not just Upload.php

Bascially CI looks in the application/libraries folder, if it finds a file called MY_{library}.php it will load the system/libraries/{library}.php file and then the application/libraries/My_{library}.php file
But if the file in application/libraries is just called {library}.php it will not load the original class to extend.
#3

[eluser]Xiphar[/eluser]
Hey tonanbarbarian
Thanks.. the documentation says that the file should be called by just the library name only. They prolly got that wrong..
However, even renaming does not solve my problem Sad I donno what else am I doing wrong..

Xiphar
#4

[eluser]tonanbarbarian[/eluser]
so summarise where you are now and what error you are getting....
#5

[eluser]Xiphar[/eluser]
It is bypassing my library altogether and goes straight to the default library.. or so it seems.

If I do not extend the CI_Upload class but manually copy paste the whole Uploads.php code and make my changes, then it works.

I suspect what's happening is the the parent function is still being called by the subclass...




Theme © iAndrew 2016 - Forum software by © MyBB