image uploader is not working in CI |
This is my view page
<?php echo form_open_multipart('admin/item/uploadImage'); ?> <input type="file" name="file" id="file" /> <td><?php echo form_submit('submit', 'Save', 'class="btn btn-primary"');?> and This is my controller page : class item extends Admin_Controller { public function __construct () { parent::__construct(); $this->load->model('item_m'); } public function index () { // Fetch all items $this->data['items'] = $this->item_m->get(); // Load view $this->data['subview'] = 'admin/item/index'; $this->load->view('admin/_layout_main', $this->data); } function uploadImage() { $config['upload_path'] = "uploads/"; $config['allowed_types'] = "gif|jpg|jpeg|png"; $config['max_size'] = "5000"; $config['max_width'] = "1907"; $config['max_height'] = "1280"; $this->upload->initialize($config); $this->load->library('upload',$config); if(!$this->upload->do_upload($_POST['file'])) { echo $this->upload->display_errors(); } else { $finfo=$this->upload->data(); $data['uploadInfo'] = $finfo; $data['thumbnail_name'] = $finfo['raw_name']. '_thumb' .$finfo['file_ext']; // $this->load->view('upload_success',$data); // You can view content of the $finfo with the code block below /*echo '<pre>'; print_r($finfo); echo '</pre>';*/ } // $this->load->view('upload_success',$data); // You can view content of the $finfo with the code block below /*echo '<pre>'; print_r($finfo); echo '</pre>';*/ }} am getting error like this A PHP Error was encountered Severity: Notice Message: Undefined index: file Filename: admin/item.php Line Number: 47 You did not select a file to upload. please help me file data is not passing to controller page? i have tried to call doupload image from another function also but it is not working also.
Thanks and Regards,
Thamaraiselvam T
You are not supposed to pass the post field to the do_upload() method. Pass it the name of the field.
Code: $this->upload->do_upload('file'); Website: http://avenir.ro
|
Welcome Guest, Not a member yet? Register Sign In |