CodeIgniter image upload

July 24, 2009

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

Entry Filed under: codeIgniter. Tags: , .

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


My Profile


# Software Eng. # Worked with C,C++, JAVA and PHP. #Love to play with codes. # Mostly like to do programming with 'C'. # I am not a CODER, but a DEVELOPER.

Admin Panel..

Life Cycle

July 2009
S S M T W T F
« Apr   Aug »
 123
45678910
11121314151617
18192021222324
25262728293031

Clouds

cakephp codeIgniter desktop htaccess jscript linux mixed my words php regular expression

Just Posted

TOP R@TED

TaGs

cakephp codeIgniter desktop GP htaccess image upload installation jscript linux news password Personal Life php regular_Xpression script session validation

Archives

Top Posts

CoMmEnTs

Blog Stats

My Web Links

Web Links

RSS Xperts.PHP