How to Upload files in Codeigniter. A simple way for beginner of CI

Author: Zeeshan Rasool  |  Mar 9, 2010 Codeigniter, Web Development

[ad#co-4]

Codeigniter has a number of libraries and helpers which you can use for making your code reliable and bugs free. CI provides an extensive library of common usage classes. Upload class in Codeigniter provides us a simple and easy way for uploading files on server.

For uploading a file using codeigniter create a simple HTML file which should contains a file input control and submit button with a form.

Here is the code:

REMEMBER : Use form_open_multipart() if you are using any uploading in the form.

Your controller will hold a simple function which will set the config array for defining the uploading path, allowed types, max size and height.

If files that are being uploaded are big in size then you need to increase Max file uploading size in php.ini on your server.

Recommended WordPress Themes Stores



If you enjoyed this post, please consider leaving a comment below or subscribing to the RSS feed to have future articles delivered to your feed reader. You can also follow us on Facebook or Twitter @99Points

This awesome post has been created by 99Points editor's team. You can follow our updates on Twitter and facebook, OR drop an email at 99points.info@gmail.com

  • arun a

    Thank you for your post i want to know how to insert a image name

  • /*— Controller —*/
    $data = array(‘upload_data’ => $this->upload->data());
    $this->load->view(‘your-upload-page’, $data);

    /*— View –*/
    echo $upload_data[‘file_name’]; //this will output the image name
    echo $upload_data[‘image_size_str’]; //this will output the width and the height of the image

    <img src="” />



Email Subscriber!

Be the first to know about new updates


Author of 99Points
Zeeshan Rasool is an experienced PHP Web Developer and founder at 99Points. Expert in Codeigniter (MVC), WordPress, JSON, jQuery & HTML5
 LinkedIn Profile  About.me


Advertisement




Friends


Categories


Popular post