0

Hi i'm having below controller in my project, Whenever i tried to run this code

$name_array = array();
        $uniqueid=uniqid();
        $count = count($_FILES['userfile']['size']);

        foreach($_FILES as $key=>$value)

        for($s=0; $s<=$count-1; $s++) {
          $_FILES['userfile']['name'] = $uniqueid.$value['name'][$s];
          $_FILES['userfile']['type']    = $value['type'][$s];
          $_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
          $_FILES['userfile']['error']       = $value['error'][$s];
          $_FILES['userfile']['size']    = $value['size'][$s];   
          $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);
          $this->upload->do_upload();
          $data = $this->upload->data();
          $name_array[] = $data['file_name'];
        }
            $names= implode(',', $name_array);
/*            $this->load->database();
            $db_data = array('id'=> NULL,
                             'name'=> $names);
        $this->db->insert('testtable',$db_data);
*/            print_r($names);

i'm getting this error.

A PHP Error was encountered

Severity: Notice

Message: Uninitialized string offset: 0

Filename: controllers/client.php

Line Number: 519

Did anybody know how to solve this error Uninitialized string offset: 0?

Vinoth Pandiyan
  • 241
  • 7
  • 19
  • Which line is 519 in the code you posted? – Dan May 14 '14 at 11:44
  • I guess you are doing some wrong coding. You are looping through `$_FILES` array and you are assigning value also. This is a big logical mistake & you are loading library with config when you do it first it works but when you load library over loop as CI uses single tone design pattern it ignores loading library so with your config it doesn't initialize. So always after loading library use `initialize` method to init it with the config data. – ARIF MAHMUD RANA May 14 '14 at 11:56
  • @Daniel like 519 is $_FILES['userfile']['name'] = $uniqueid.$value['name'][$s]; – Vinoth Pandiyan May 14 '14 at 12:13

0 Answers0