save uploaded image in database by using codeigniter

Today, We want to share with you file upload in codeigniter.In this post we will show you multiple files upload in codeigniter with example, hear for files upload and download in codeigniter we will give you demo and example for implement.In this post, we will learn about How To Upload Image In Codeigniter Mysql Database And Display? with an example.

Free Live Chat for Any Issue

Codeigniter File Upload | Image Upload Library Example

Upload Form(Html View)

<html>
<head>
<title>Upload File Form</title>
</head>
<body>

<?php echo $error;?>

<?php echo form_open_multipart('upload/process_upload');?>

<input type="file" name="myfile" />

<input type="submit" value="Upload File" />

</form>

</body>
</html>

Codeigniter File Upload Controller Example:

<?php

class Upload extends CI_Controller {

        public function __construct()
        {
                parent::__construct();
                $this->load->helper(array('form', 'url'));
        }

        public function index()
        {
                $this->load->view('upload_form_view', array('error' => ' ' ));
        }

        public function process_upload()
        {
                $config['upload_path']          = './uploads/';
                $config['allowed_types']        = 'gif|jpg|png';
                $config['max_size']             = 2048;
                $config['max_width']            = 1000;
                $config['max_height']           = 800;
                $this->load->library('upload', $config);

                if ( ! $this->upload->process_upload('myfile'))
                {
                        $error = array('error' => $this->upload->display_errors());

                        $this->load->view('upload_form_view', $error);
                }
                else
                {
                        $data = array('upload_data' => $this->upload->data());

                        $this->load->view('success_view', $data);
                }
        }

}
?>

Success Page(Html View)

<html>
<head>
<title>Upload Success - www.pakainfo.com</title>
</head>
<body>

<h3>The file was successfully uploaded.</h3>

<ul>
<?php foreach ($upload_data as $product => $value):?>
<li><?php echo $product;?>: <?php echo $value;?></li>
<?php endforeach; ?>
</ul>

<p><?php echo anchor('upload', 'Upload Other File!'); ?></p>

</body>
</html>

I hope you get an idea about files upload in codeigniter using database.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.