In Codeigniter upload image file with directory is very easy. You need to use form_open_multipart() for uploading image file into MySQl table or Database using Codeigniter framework.
CODEIGNITER is a PHP framework and its study is simple and easy. It is a powerful PHP framework with a very small footprint. This framework is built for developers who need a simple and elegant toolkit to create full-featured web applications or create a Project of CODEIGNITER.
This tutorial I will show you how to upload image into database with a directory in Codeigniter. So follow the steps:
1) Create a form page and use in form form_open_multipart() and create a directory for file upload.
2) Set a URL link in form that’s like Controller/file_upload.
3) Call the function name in controller page, which define in form URL link.
4) Use some helper and set under the function __construct(),
5) Get value from input file and store in a array variable,
6) Set the path or directory,
7) Pass the array value in the model page and submit value using insert query
Example and source code:
Form:
<!DOCTYPE html> <html> <head> <title>Upload Image</title> </head> <body> <?php $fcl=array('class'=>'form-control','id'=>'form'); echo form_open_multipart('Controller/file_upload',$fcl); ?> <div class="form-group"> <label class="control-label"> Upload File <span class="symbol required"></span> </label> <input type="file" class="form-control" name="file_name"/> <input type="submit" class="btn btn-primary" value="Upload"> </div> <?php echo form_close(); ?> </body> </html>
Controller:
<?php class Controller extends CI_Controller { function __construct() { parent::__construct(); $this->load->helper('url'); $this->load->helper('form'); $this->load->database(); $this->load->model('Model'); } public function file_upload(){ $config['upload_path'] = './assets/images/'; $config['allowed_types'] = '*'; $this->load->library('upload', $config); $this->upload->do_upload('file_name'); $up_file_name = $this->upload->data(); $data = array('file_upload' => $up_file_name['file_name']); $this->Model->FileUpload($data); } } ?>
Model:
<?php function FileUpload($data){ $this->db->insert('Table Name',$data); } ?>
tutorial is very helpful thank you
upload image with csv url in codeigniter