hi, friends today I will show you the best and easiest steps to upload image in Codeigniter. I will show you how to upload the image by using a single optimize function in Codeigniter.

Steps to follow

  • Create the assets folder/dir in the application folder/dir.
  • Create uploads folder/dir in the assets folder/dir.
  • Add enctype=”multipart/form-data” in your form tag.
  • Add “input type file” tag in the form
  • copy the below function do upload in your control.
  • Call your function in the post request where you are submitting your form

$image['image'] = $this->do_upload('image');

now in this the name “image” in $this->do_upload(‘image’); is the name of file form input tag as we set in form.

$image[‘image’] is the unique name of an image generated by the function you can view image in assets/uploads dir we create in 1st step and you insert the image name in the database.

Good luck guys, I will write the next tutorial on how to upload images and store name into database.

News Reporter