How to Upload Image files Using Codeigniter? Codeigniter's Upload class Library
gives no hint for how to upload a image using simple form and upload the image to it's images folder which is present in the root directory...
Thanks in advance..
How to Upload Image files Using Codeigniter? Codeigniter's Upload class Library
gives no hint for how to upload a image using simple form and upload the image to it's images folder which is present in the root directory...
Thanks in advance..
Here is an example. Hope this would help you :)
in your controller. lets say upload.php
public function upload() {
if($this->input->post('upload')) {
$config['upload_path'] = APPPATH . 'your upload folder name here/';
$config['file_name'] = filename_here;
$config['overwrite'] = TRUE;
$config["allowed_types"] = 'jpg|jpeg|png|gif';
$config["max_size"] = 1024;
$config["max_width"] = 400;
$config["max_height"] = 400;
$this->load->library('upload', $config);
if(!$this->upload->do_upload()) {
$this->data['error'] = $this->upload->display_errors();
} else {
//success
}
}
}
Then in your view
<?php echo form_open_multipart('upload'); ?>
<?php echo form_upload('userfile'); ?><br />
<?php echo form_submit('upload', 'Upload');?>
<?php echo form_close(); ?>