how to upload image via codeIgniter function in PHP

how to upload image via codeIgniter function in PHP
November 26, 2018 No Comments Android Development,Development,iOS Development Pushpendra Kumar

Here you can see the PHP CodeIgniter code for uploading the Image via android or iOS. For iOS you can refer a video. For watching the video please click here.

This post is about CodeIgniter(C.I.) file upload. By the use of file uploading class, you can easily upload a file or an image. One can easily validate and restrict file type, its size and can even provide various preferences while uploading a file or image.Using CodeIgniter Image Upload example, we will teach you how an image or a file gets uploaded to an upload folder or a targeted location.

Below is our complete code with live demo and download code option.

function file_upload() {
       // key name is file_name
       if (!empty($_FILES)) {
           $config['upload_path'] = $uploads_path;
           $config['allowed_types'] = 'gif|jpg|png|jpeg';
           $config['overwrite'] = FALSE;
           $config['encrypt_name'] = TRUE;
           $config['remove_spaces'] = TRUE;
           $this->load->library('upload', $config);
           if (!$this->upload->do_upload('file_name')) {
               $this->data['error'] = array('error' => $this->upload->display_errors());
               $arr = array('status' => "invalid", "message" => strip_tags($this->data['error']["error"]), "title" => "invalid", "error" => strip_tags($this->data['error']));
           } else {
               $data = array('upload_data' => $this->upload->data());
               $file_name = $data["upload_data"]["file_name"];
               $arr = array('status' => "valid", "message" => "Image Uploaded","file_name" => $file_name, "file_path" => $this->base.$file_name);
           echo json_encode($arr);

SELECT * or SELECT column1, colum2, column3, etc

Good luck 🙂 Happy Coding

About The Author
Pushpendra Kumar I am passionate about mobile application development and professional developer at Colour Moon Technologies Pvt Ltd ( This website I have made so that I can meet with new challenges and can share here.

Leave a reply

Your email address will not be published. Required fields are marked *