Get multiple file data information after upload success codeigniter -


when upload multiple images able display each file name.

i can upload file fine in upload folder, when try multiple file_name data shows error below.

i error below

severity: warning message: illegal string offset 'file_name' filename: page/page_add.php line number: 110

which here in success part of upload function

$upload_info = $this->upload->data();  foreach ($upload_info $upload_data) {     echo $upload_data['file_name']; // line 110 } 

do upload function

public function do_upload() {     $directory = fcpath . 'uploads/';      if (is_dir($directory)) {          foreach ($_files $field_name => $value) {              if ($value['name'] != '') {                  $this->load->library('upload');                  $this->upload->initialize($this->do_upload_options());                  if (!$this->upload->do_upload($field_name)) {                      $this->form_validation->set_message('do_upload', $this->upload->display_errors());                      return false;                  } else {                      $upload_info = $this->upload->data();                      foreach ($upload_info $upload_data) {                         echo $upload_data['file_name'];                     }                   }              }         }      } else {          $this->form_validation->set_message('do_upload', 'cannot find directory' .' '. $directory);          return false;      } }  public function do_upload_options() {     $config = array();      $config['upload_path'] = fcpath . 'uploads/';     $config['allowed_types'] = 'gif|png|jpg';     $config['max_size'] = '30000';     $config['overwrite'] = true;     $config['max_width']  = '0';     $config['max_height']  = '0';      return $config; } 

each field name has own name="" example name="fileupload_extra_image0" number @ end automatically generated

vardump

array(2) { ["fileupload_extra_image0"]=> array(14) { ["file_name"]=> string(17) "ci_logo_flame.jpg" ["file_type"]=> string(10) "image/jpeg" ["file_path"]=> string(49) "c:/xampp/htdocs/riwakawebsitedesigns-cms/uploads/" ["full_path"]=> string(66) "c:/xampp/htdocs/riwakawebsitedesigns-cms/uploads/ci_logo_flame.jpg" ["raw_name"]=> string(13) "ci_logo_flame" ["orig_name"]=> string(17) "ci_logo_flame.jpg" ["client_name"]=> string(17) "ci_logo_flame.jpg" ["file_ext"]=> string(4) ".jpg" ["file_size"]=> float(3.61) ["is_image"]=> bool(true) ["image_width"]=> int(100) ["image_height"]=> int(100) ["image_type"]=> string(4) "jpeg" ["image_size_str"]=> string(24) "width="100" height="100"" } ["fileupload_extra_image1"]=> array(14) { ["file_name"]=> string(10) "family.png" ["file_type"]=> string(9) "image/png" ["file_path"]=> string(49) "c:/xampp/htdocs/riwakawebsitedesigns-cms/uploads/" ["full_path"]=> string(59) "c:/xampp/htdocs/riwakawebsitedesigns-cms/uploads/family.png" ["raw_name"]=> string(6) "family" ["orig_name"]=> string(10) "family.png" ["client_name"]=> string(10) "family.png" ["file_ext"]=> string(4) ".png" ["file_size"]=> float(828.1) ["is_image"]=> bool(true) ["image_width"]=> int(670) ["image_height"]=> int(450) ["image_type"]=> string(3) "png" ["image_size_str"]=> string(24) "width="670" height="450"" } }  

public function do_upload()  {     $directory = fcpath . 'uploads/';     $upload_info = [];//array();      if (is_dir($directory)) {          foreach ($_files $field_name => $value) {              if ($value['name'] != '') {                  $this->load->library('upload');                  $this->upload->initialize($this->do_upload_options());                  if (!$this->upload->do_upload($field_name)) {                      $this->form_validation->set_message('do_upload', $this->upload->display_errors());                      return false;//you make better control here because first 1 not file_name break process                  } else {                      $upload_info[$field_name] = $this->upload->data();                  }             }         }          if ( count($upload_info) > 0 ) {             foreach ($upload_info $upload_data) {                 echo $upload_data['file_name'];             }         }      } else {          $this->form_validation->set_message('do_upload', 'cannot find directory' .' '. $directory);          return false;      } }  public function do_upload_options()  {     $config = array();      $config['upload_path'] = fcpath . 'uploads/';     $config['allowed_types'] = 'gif|png|jpg';     $config['max_size'] = '30000';     $config['overwrite'] = true;     $config['max_width']  = '0';     $config['max_height']  = '0';      return $config; } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -