doutuo7126 2013-08-24 21:40
浏览 28

在CodeIgniter中上传图像不起作用

I have view that upload images and i do input type file like:

<input type="file" name="ev_pic" size="20" />

and my controller like:

if(strlen($_FILES['ev_pic']['name']) > 0) 
        {
        $pic = $this->do_upload('ev_pic');
        }

do upload method:

public function do_upload($field) {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '1000';
        $config['max_width'] = '1024';
        $config['max_height'] = '768';

        $this->load->library('upload', $config);

        if (!$this->upload->do_upload($field)) {
            $error = array('error' => $this->upload->display_errors());

            return $error;
        } else {
            /*$data = array('upload_data' => $this->upload->data());
            return $data;*/
            $updata =$this->upload->data();
            $data = $updata['raw_name'].$updata['file_ext'];
            return $data;
        }
    }

in debug its show me this error:

Severity: Notice

Message: Undefined index: ev_pic

Filename: administrator/events.php

Line Number: 68


Error Number: 1054

Unknown column 'Array' in 'field list'

UPDATE `events` SET `ev_id` = 0, `ev_text` = 0, `ev_pic` = Array

Filename: D:\AppServ\www\d5nashaqa2\system\database\DB_driver.php

Line Number: 330

So i will named file by ev_pic, where is the problem?

  • 写回答

2条回答 默认 最新

  • duankuangxie9070 2013-08-25 05:01
    关注

    please check your form

    form enctype="multipart/form-data" is avaliable or not

    and change this line

    if (!$this->upload->do_upload($field)) { to if (!$this->upload->do_upload('ev_pic')) {

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类