CodeIgniter image upload

When I first time try to write code for image upload on Codeigniter, I had to face problems. I dig and dig and dig. I search on CI guide. but, thats not enough to help me. Well, finally I did it.  If someone stuck on CI image upload, hope it will help them a lot.

There are some easy steps to upload image on CI :

  • Create the form normally how it should create for upload a photo on php.  Must add “enctype=”multipart/form-data”
  • open controler file. under the upload image function write down following code :
  • $config[ ‘upload_path’ ] =  ‘./uploads/’ ;  // destination folder path
  • $config[ ‘allowed_types’ ]  =  ‘gif|jpg|png’ ; // Allowed uploaded file type
  • $config[ ‘max_size’ ]    =  ‘2048’ ;// Allowed uploaded file’s max size
  • $this->load->helper( array(  ‘form’ ,  ‘url’ ) ) ;
  • $this->load->library( ‘upload’ ,  $config);
  • $image_up = $this->upload->do_upload(‘image‘);
  • $image_data =  array(‘upload_data’ => $this->upload->data());
  • $image_up is where image upload information will be safe, it will return 1 if image uploaded successfully.
  • $config is very important variable. for details of  “$config” variable’s parameters  you must have to see the manual
  • $image_data will carry the uploaded image information.
  • BLUE marked words are library function.
  • image is form name

4 thoughts on “CodeIgniter image upload

  1. Woah! I’m really digging the template/theme of this website. It’s simple, yet effective.

    A lot of times it’s tough to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a
    very good job with this. Also, the blog loads very quick for
    me on Firefox. Exceptional Blog!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s