php - Codeingiter : Image upload through web services -


i trying upload 1 image through web services . following code

  public function upload() {         $config['upload_path']          = './uploads/';         $config['allowed_types'] = 'gif|jpg|png|mp4|jpeg';         $config['max_size']             = 100;         $config['max_width']            = 1024;         $config['max_height']           = 768;         $this->load->library('upload', $config);         $this->upload->initialize($config);          $this->data['data']= $_files;           echo json_encode($this->data); die;           if ( ! $this->upload->do_upload('userfile'))         {                 $error = array('error' => $this->upload->display_errors());                 $this->data['data']= $error ;                  echo json_encode($this->data['data']);                  die;          }         else         {                 $data = array('upload_data' => $this->upload->data());                                         $this->data['data']= 'done' ;                   echo json_encode($this->data['data']);                  die;          } } 

if json_encode($_files) response on mobile

 data =     {         userfile =         {             error = 0;             name = pen;             size = 38238;             "tmp_name" = "/tmp/phpeseqnk";             type = jpeg;         };     }; 

when print errors array

error = "<p>the filetype attempting upload not allowed.</p>"; 

please check both responses printed , let me know how can fix .

try this. might help

$config["allowed_types"] = "image/jpeg|image/gif|image/jpg|image/png|video/mp4"; 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -