图像上传器在 CI 中不起作用


image uploader is not working in CI

这是我的视图页面

<?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"');?>

这是我的控制器页面:

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>';*/

}}

我收到这样的错误

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.

请帮我文件数据没有传递到控制器页面? 我也尝试从另一个函数调用 doupload 图像,但它也不起作用。

问题出在这个语句上:

if(!$this->upload->do_upload($_POST['file']))

在这里,您只需要指定参数名称,例如:

if(!$this->upload->do_upload('file'))