0

I have view that upload images and i do input type file like:

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

and my controller like:

if(strlen($_FILES['ev_pic']['name']) > 0) 
        {
        $pic = $this->do_upload('ev_pic');
        }

do upload method:

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

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

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

            return $error;
        } else {
            /*$data = array('upload_data' => $this->upload->data());
            return $data;*/
            $updata =$this->upload->data();
            $data = $updata['raw_name'].$updata['file_ext'];
            return $data;
        }
    }

in debug its show me this error:

Severity: Notice

Message: Undefined index: ev_pic

Filename: administrator/events.php

Line Number: 68


Error Number: 1054

Unknown column 'Array' in 'field list'

UPDATE `events` SET `ev_id` = 0, `ev_text` = 0, `ev_pic` = Array

Filename: D:\AppServ\www\d5n\rashaqa2\system\database\DB_driver.php

Line Number: 330

So i will named file by ev_pic, where is the problem?

7
  • Post your do upload method Commented Aug 24, 2013 at 21:42
  • possible duplicate of Reference - What does this error mean in PHP? Commented Aug 24, 2013 at 21:42
  • @userNOID i will edit my post Commented Aug 24, 2013 at 21:44
  • Undefined notices fix with isSet() and your SQL error try use apostrofes. Commented Aug 24, 2013 at 21:50
  • i will try this :- if(isset($_FILES['ev_pic']['name'])) { $pic = $this->do_upload('ev_pic'); } and call me error :- Message: Undefined variable: pic Commented Aug 24, 2013 at 22:00

2 Answers 2

1

load upload library in __construct function of your controller like this:

public function __construct(){
  parent::__construct();
  $this->load->library('upload');
}

then change your function to below:

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

        /////////// change this //// //////
        $this->upload->initialize($config);
        ///////////////////////////////////

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

            return $error;
        } else {
            /*$data = array('upload_data' => $this->upload->data());
            return $data;*/
            $updata =$this->upload->data();
            $data = $updata['raw_name'].$updata['file_ext'];
            return $data;
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

0

please check your form

form enctype="multipart/form-data" is avaliable or not

and change this line

if (!$this->upload->do_upload($field)) { to if (!$this->upload->do_upload('ev_pic')) {

1 Comment

First part yes, missing enctype attribute could be the issue, but no need to change the code, the value for $field is correctly being passed as an argument to the function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.