• RSS
  • Facebook
  • Twitter

PHP, Mysql, Codeigniter,ruby on rails, fedora,ubuntu,wordpress, Gnome3, HTML5, CSS3, Jquery, GIMP programming.

Sponsored Links

Code Igniter Image Uploader / File Uploader – Multiple Files

Categories: CodeIgniter, Featured, web
Sponsored Links

Code Igniter Image Uploader

Creating an image uploader or file uploader is a big problem in web domain coding. Code Igniter Made it easy for you. It uses two classes File Uploading Class and Image Manipulation Class. Great Programme made for save the life of a web developer. I Got a detailed post from Jefim Boressov (The Mighty Web Developer)’s Blog. And It was Great. I am copying the code for my future reference. Thanks Jefim.

Image / file upload with CodeIgniter

Image upload is difficult for web developer. And even though CI has a lot to offer (in the means of documentation) it still lacks a direct copy-paste code on their website so that people can just put it into their controller and use away.
Here we will have:

  • Image upload form with 5 images
  • And a controller function that will upload those
  • Thumbnails will be there too ;)

Ok, lets start with the HTML form code, it is very basic:
views/upload_form.php

<form method="post" action="uploader/go" enctype="multipart/form-data">
  <input type="file" name="image1" /><br />
  <input type="file" name="image2" /><br />
  <input type="file" name="image3" /><br />
  <input type="file" name="image4" /><br />
  <input type="file" name="image5" /><br />
  <input type="submit" name="go" value="Upload!!!" />
</form>

And now the controller:
controllers/Uploader.php

class Uploader extends Controller {
  function go() {
    if(isset($_POST['go'])) {
      /* Create the config for upload library */
      /* (pretty self-explanatory) */
      $config['upload_path'] = './assets/upload/'; /* NB! create this dir! */
      $config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
      $config['max_size']  = '0';
      $config['max_width']  = '0';
      $config['max_height']  = '0';
      /* Load the upload library */
      $this->load->library('upload', $config);

      /* Create the config for image library */
      /* (pretty self-explanatory) */
      $configThumb = array();
      $configThumb['image_library'] = 'gd2';
      $configThumb['source_image'] = '';
      $configThumb['create_thumb'] = TRUE;
      $configThumb['maintain_ratio'] = TRUE;
      /* Set the height and width or thumbs */
      /* Do not worry - CI is pretty smart in resizing */
      /* It will create the largest thumb that can fit in those dimensions */
      /* Thumbs will be saved in same upload dir but with a _thumb suffix */
      /* e.g. 'image.jpg' thumb would be called 'image_thumb.jpg' */
      $configThumb['width'] = 140;
      $configThumb['height'] = 210;
      /* Load the image library */
      $this->load->library('image_lib');

      /* We have 5 files to upload
       * If you want more - change the 6 below as needed
       */
      for($i = 1; $i < 6; $i++) {
        /* Handle the file upload */
        $upload = $this->upload->do_upload('image'.$i);
        /* File failed to upload - continue */
        if($upload === FALSE) continue;
        /* Get the data about the file */
        $data = $this->upload->data();

        $uploadedFiles[$i] = $data;
        /* If the file is an image - create a thumbnail */
        if($data['is_image'] == 1) {
          $configThumb['source_image'] = $data['full_path'];
          $this->image_lib->initialize($configThumb);
          $this->image_lib->resize();
        }
      }
    }
    /* And display the form again */
    $this->load->view('upload_form');
  }
}

 

Also You can use the HTML 5 Image uploader for uploading multiple files without flash. The New HTML5 Drag and Drop feature also work with codeigniter . Check the detailes about Jquery HTML5 File Uploader for Codeigniter . Also You can download the source file from GitHub  blueimp / jQuery-File-Upload .

And that is it. Customize it to your needs, the basics are there already. And good luck!

Enhanced by Zemanta
Amplify

Related Articles:

  1. Code Igniter for Beginners in Fedora 11
  2. Handle 404, 500, and 301 Apache Errors With .htaccess file

Related Keys:

  • image upload error in codeigniter
  • blueimp jquery file upload with mvc3
  • resize image multiple in codeigniter
  • upload photo with codeigniter tutorial
  • mengupload gambar ke database codeigniter
  • multi image upload codeignitor
  • how to paste input type file
  • jquery upload with codeigniter
  • how to upload multiple files to folder in codeigniter
  • codeigniter photo upload
  • save file into database by codeiginiter
  • codeignter upload file too big
  • how to upload files using codeigniter
  • jquery image upload and codeigniter
  • source upload download file di ci
  • multiple image upload using ci
  • source code to move images in codeigniter
  • multiple image upload in codeigniter
  • codigniter multiple image upload
  • jquery image upload in codeigniter
  • upload file codeigniter
  • ci upload multiple files library
  • ajaxupload codeigniter
  • codeigniter upload file to database
  • thumbs examples in codeigniter
  • file uploading class codeigniter
  • ajax large file upload codeigniter
  • video upload and insert using ci and mysql
  • jquery igniter upload
  • upload file codeigniter save log
  • how to use upload crating thumb codeigniter
  • codeigniter upload and thumnails
  • jquery ajax codeigniter upload file
  • create update image gallery with codeigniter
  • file upload thumbs in ci
  • Adding Form images With JQuery and Saving to a Database
  • how to upload multple images using codeigniter
  • uploadr codeigniter
  • codeingniete photo upload ajax
  • how to image upload in codeigniter
  • fedora facebook photo uploader
  • get thumbnail image filename codeigniter
  • jquery multiple file upload in codeigniter
  • codeigniter : how to upload multiple images
  • multiple upload image with ajax and mysql
  • codeigniter upload suffix
  • multiple file upload in codeigniter
  • insert data image to database codeigniter
  • adding multiple input file and upload codeigniter
  • codeigniter upload image mysql
  • Pingback: Trackback @ Watch Movies Online Free

  • Fila

    Tnx, great post, helped me alot.

  • http://www.bz7.biz Romeo

    at a time, how do i insert those image data into database? can u give me a code about it??

    • http://ranjith.itpublic.in ranjith siji

      Dear Romeo. Uploading images into a MySQL database table is a bad idea . If you want to insert the image file name into a database just call a model function in your controller. I can provide help. You just send an email to me. or post the detailed situation on the Contact Form. Thanks–