Rectangle 27 1

How to upload image in CodeIgniter?


//this is the code you have to use in you controller 

        $config['upload_path'] = './uploads/';  

// directory (http://localhost/codeigniter/index.php/your directory)

        $config['allowed_types'] = 'gif|jpg|png|jpeg';  
//Image type  

        $config['max_size'] = 0;    

 // I have chosen max size no limit 
        $new_name = time() . '-' . $_FILES["txt_file"]['name']; 

//Added time function in image name for no duplicate image 

        $config['file_name'] = $new_name;

//Stored the new name into $config['file_name']

        $this->load->library('upload', $config);

        if (!$this->upload->do_upload() && !empty($_FILES['txt_file']['name'])) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('production/create_images', $error);
        } else {
            $upload_data = $this->upload->data();   
        }
Note
Rectangle 27 1

How to upload image in CodeIgniter?


$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');

File uploads are an essential process in many web apps. Almost every website and web app requires an integrated file upload component. File and image upload in CodeIgniter powered app is a simple component that takes care of the upload process with little issues.

I will also set the preferences for the file upload process through the controller function do_upload(). this function will contain the following code:

The next step is the creation of a file in the controller folder. Name the file upload_controller.php. In this file, I will load a library for initializing the Upload class through the following code:

Note
Rectangle 27 0

How to upload image in CodeIgniter?


$_FILES
$this->do_upload();
// Change the 'second_method' to your method name
echo form_open_multipart('welcome/second_method');
// Load the helper files within the Controller
$this->load->helper('form');
$this->load->helper('url');
<form method="post" action="controller/method" enctype="multipart/form-data" />
NULL
form_open_multipart()
var_dump($data['upload_data']);
welcome/second_method

Also there are couple of articles/samples about the file uploading in CodeIgniter, you might want to consider:

CodeIgniter has documented the Uploading process very well, by using the File Uploading library.

It seems the problem is you send the form request to welcome/do_upload, and call the Welcome::do_upload() method in another one by $this->do_upload().

Just as a side-note: Make sure that you've loaded the url and form helper functions before using the CodeIgniter sample code:

Then change the form helper function (within the View) as follows1:

You could take a look at the sample code in the user guide; And also, in order to get a better understanding of the uploading configs, Check the Config items Explanation section at the end of the manual page.

Note
Rectangle 27 0

How to upload image in CodeIgniter?


$_FILES
$this->do_upload();
// Change the 'second_method' to your method name
echo form_open_multipart('welcome/second_method');
// Load the helper files within the Controller
$this->load->helper('form');
$this->load->helper('url');
<form method="post" action="controller/method" enctype="multipart/form-data" />
NULL
form_open_multipart()
var_dump($data['upload_data']);
welcome/second_method

Also there are couple of articles/samples about the file uploading in CodeIgniter, you might want to consider:

CodeIgniter has documented the Uploading process very well, by using the File Uploading library.

I stumbled on this Q&A from a Google search for another question. You may want to update your answer with the following link codeigniter.com/userguide3/libraries/ as the ellislab.com/codeigniter/user-guide/libraries/ library is out of date.

It seems the problem is you send the form request to welcome/do_upload, and call the Welcome::do_upload() method in another one by $this->do_upload().

Just as a side-note: Make sure that you've loaded the url and form helper functions before using the CodeIgniter sample code:

Then change the form helper function (within the View) as follows1:

You could take a look at the sample code in the user guide; And also, in order to get a better understanding of the uploading configs, Check the Config items Explanation section at the end of the manual page.

Note
Rectangle 27 0

How to upload image in CodeIgniter?


public function doupload()
     {
        $upload_path="https://localhost/project/profile"  
        $uid='10'; //creare seperate folder for each user 
        $upPath=upload_path."/".$uid;
        if(!file_exists($upPath)) 
        {
                   mkdir($upPath, 0777, true);
        }
        $config = array(
        'upload_path' => $upPath,
        'allowed_types' => "gif|jpg|png|jpeg",
        'overwrite' => TRUE,
        'max_size' => "2048000", 
        'max_height' => "768",
        'max_width' => "1024"
        );
        $this->load->library('upload', $config);
        if(!$this->upload->do_upload('userpic'))
        { 
            $data['imageError'] =  $this->upload->display_errors();

        }
        else
        {
            $imageDetailArray = $this->upload->data();
            $image =  $imageDetailArray['file_name'];
        }

     }

Simple Image upload in codeigniter

Note