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'))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名