Question

i have a problem with codeigniter upload form

View.php I found this code in Codeigniter documentation and i dont know where is the problem..

    <?php echo $error;?>
<?php echo form_open_multipart('upload/do_upload');?>
<input type="file" name="userfile" size="20" />
<br /><br />
<input type="submit" value="upload" />
</form>

upload.php Thats upload.php

<?php
 defined('BASEPATH') OR exit('No direct script access allowed');
    class Upload extends CI_Controller {

function __construct()
{
    parent::__construct();
    $this->load->helper(array('form', 'url'));
}

function index()
{
    $this->load->view('upload_form', array('error' => ' ' ));
}

function do_upload()
{
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '100';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';

    $this->load->library('upload', $config);

    if ( ! $this->upload->do_upload())
    {
        $error = array('error' => $this->upload->display_errors());

        $this->load->view('upload_form', $error);
    }
    else
    {
        $data = array('upload_data' => $this->upload->data());

        $this->load->view('upload_success', $data);
    }
}
  }
     ?>

When i upload some image ci give me

    A PHP Error was encountered

Severity: Notice

Message: Undefined property: Upload::$upload

Filename: controllers/Upload.php

Line Number: 52

Backtrace:
    Fatal error: Call to a member function do_upload() on a non-object in

Where is the problem ?Thanks

Was it helpful?

Solution

EDIT:

From the link you posted I followed the guide on uploading the file and it worked perfectly fine.

Make sure you have CI setup properly:

The folders application and system and the file index.php must be uploaded to your working webserver, you must then create a folder called uploads, make sure this folder is writable by the proper user, for my system it is www-data. I'm using apache2 with linux so my webroot is var/www.

So you should see in the primary folder:

  • application
  • system
  • uploads
  • index.php

After you do that you will go to:

localhost/index.php/upload/ or your proper path for index.php/upload/ and test this again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top