1
votes

Hello i am anew to code igniter. My problem is When i am trying to upload an image during the project creation and i am getting the following error.

"A PHP Error was encountered

Severity: Notice

Message: Undefined property: Home::$upload

Filename: controllers/home.php

Line Number: 68

Fatal error: Call to a member function initialize() on a non-object in application/controllers/home.php on line 68"

My code is

class Home extends CI_Controller 
{

public function index()
{
    $this->load->model("content_model");

    if (!$this->user->loggedin) {
        $projects = $this->content_model->get_projects();
    } else {
        $projects = $this->content_model
            ->get_user_projects($this->user->info->ID);
    }
    $icons = $this->content_model->get_icons();
    $this->template->loadContent("home/index.php", array(
        "icons" => $icons, 
        "projects" => $projects
        )
    );
}

and the error occuring line 68 is this,

$image = "";
    if ($_FILES['userfile']['size'] > 0 
            && $this->settings->info->project_upload_icon) {
        $this->upload->initialize(array( 
           "upload_path" => $this->settings->info->upload_path,
           "overwrite" => FALSE,
           "max_filename" => 500,
           "encrypt_name" => TRUE,
           "remove_spaces" => TRUE,
           "allowed_types" => "gif|jpg|png|jpeg",
           "max_size" => 3000,
           "xss_clean" => TRUE,
           "max_width" => 92,
           "max_height" => 92
        ));

Please help me to sove this problem

1
The error description is pretty self explanatory, isn't it? - zerkms
Did you put in auto-loads the upload library ? EDIT : don't forget to load it with : $this->load->library('upload'); - Bobot
@Bobot thank you very much. Really you saved a lot of time for me. - Sai

1 Answers

1
votes

You need to load the "upload" libarary either in autoload.php page or in the corresponding controller page so that it can recognize the upload object. In autoload.php you just need to add the name of the library in the library array.