Welcome Guest, Not a member yet? Register   Sign In
Codeigniter 3 upload image
#1

[eluser]Unknown[/eluser]
Hi guys, i have big problem with ci upload form...

view.php
Code:
<html>
<head>
<title>Upload Form</title>
</head>
<body>

<?php echo $error;?>

<?php echo form_open_multipart('upload/do_upload');?>

<input type="file" name="userfile" size="20" />

<br /><br />

&lt;input type="submit" value="upload" /&gt;

&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;


controller- > upload.php
Code:
&lt;?php

class Upload extends CI_Controller {

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

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

        public 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);
                }
        }
}
?&gt;

And when i upload some image file
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Upload::$upload

Filename: controllers/Upload.php

Line Number: 32

Fatal error: Call to a member function do_upload() on a non-object in  ....  on line 32
A PHP Error was encountered

Severity: Error

Message: Call to a member function do_upload() on a non-object

Filename: controllers/Upload.php

Line Number: 32

Backtrace:

Where is the problem ? I tried everything and i cant fix it ..
#2

[eluser]ivantcholakov[/eluser]
Code:
class Upload extends CI_Controller {

A wild guess: Rename the class.

Edit: ... not to be "Upload"

Code:
class Uploadimage extends CI_Controller {

I think the class name "Upload" tricks the loader that the library CI_Upload has been loaded.




Theme © iAndrew 2016 - Forum software by © MyBB