douqin0676 2015-01-19 07:45
浏览 24
已采纳

图像上传器在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.

  • 写回答

1条回答 默认 最新

  • doujiao7325 2015-01-19 07:52
    关注

    The problem is with this statement :

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

    Here you have to specify only parameter name, like :

    if(!$this->upload->do_upload('file'))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据