php - Codeigniter : file uploading through mobile -


i using following code upload file .

$this->load->library('upload');              $files = $_files;              $cpt = count($_files['userfile']['name']);             $this->data['data']= $files;               $this->upload->initialize($this->set_upload_options());             for($i=0; $i<$cpt; $i++) {                   $_files['userfile']['name']= $files['userfile']['name'][$i];                 $_files['userfile']['type']= $files['userfile']['type'][$i];                 $_files['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];                 $_files['userfile']['error']= $files['userfile']['error'][$i];                 $_files['userfile']['size']= $files['userfile']['size'][$i];                       $this->data['name']= $_files['userfile']['name'];                  $this->data['type']= $_files['userfile']['type'];                   if($this->upload->do_upload()){                      $this->db->insert('attachment', array(                         'type'      =>   'quotation',                         'typeid'    =>   $lastid,                          'path'      =>   $_files['userfile']['name'],                         'extension' =>   $_files['userfile']['type'],                      ));                     $this->data['message'] = 'file uplaoded';                  }                 else {                     $this->data['message'] = $this->upload->display_errors();                   }             }             echo json_encode($this->data); die;   private function set_upload_options()     {            //upload image options         $config = array();         $config['upload_path'] = './uploads/';         $config['allowed_types'] = 'gif|jpg|png|mp4|jpeg';         $config['max_size']      = '*';         $config['overwrite']     = false;           return $config;     } 

following output in

 data =     {         userfile =         {             error = 0;             name = imgname;             size = 146245;             "tmp_name" = "/tmp/phppylh8a";             type = "image/jpeg";         };     };     message = "<p>you did not select file upload.</p>";     name = s;     type = i; 

this mobile developer gets in response .

if try following files uploaded

 <form action="formlink" method="post" accept-charset="utf-8" enctype="multipart/form-data"> <input type="file" name="userfile[]"   /> <input type="file" name="userfile[]"   />  <br /><br />  <input type="submit" value="upload" />  </form> 

please me how can fix

you need use below code uploading data:

$config = array(             'upload_path' => $path,             'allowed_types' => 'jpg|gif|png|jpeg',             'overwrite' => 1,             );             $this->load->library('upload', $config);             $images = array();             foreach ($files['name'] $key => $image) {                 if ($image != '') {                     $_files['userfile[]']['name'] = $files['name'][$key];                     $_files['userfile[]']['type'] = $files['type'][$key];                     $_files['userfile[]']['tmp_name'] = $files['tmp_name'][$key];                     $_files['userfile[]']['error'] = $files['error'][$key];                     $_files['userfile[]']['size'] = $files['size'][$key];                     $image = str_replace(' ', '_', $image);                     $filename = time() . '_' . $image;                     $images[] = $filename;                     $config['file_name'] = $filename;                     $this->upload->initialize($config);                     if ($this->upload->do_upload('images[]')) {                         $this->upload->data();                     } else {                         return false;                     }                 }             } 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -