doutui9606 2013-07-26 09:35
浏览 48
已采纳

使用CodeIgniter上传ajax文件时的错误处理

With CodeIgniter 2.1.4 I'm trying to upload a file using ajax and the File Uploading Class. I have the construct in the Controller as:

public function __construct()
{
    parent::__construct();
    $this->load->helper(array('form', 'url'));
}

And my upload function in the Controller as:

public function upload_file()
{

    $config['upload_path'] = 'upload/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '100';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';

    $this->load->library('upload', $config);
    if (!$this->upload->do_upload())
    {
        $error = array('error' => $this->upload->display_errors());
        $result['success'] = 1;
        $result['message'] = $error;
    }
    else
    {
        $result['success'] = 0;
        $result['message'] = "Successful Upload";
    }

    die(json_encode($result));

}

But the errors are coming out as:

Array

How can I get the error message out of the array?

  • 写回答

2条回答 默认 最新

  • dsij89625 2013-07-26 09:38
    关注

    Change this line and try:

    $result['message'] = $error['error'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 优质github账号直接兑换rmb,感兴趣伙伴可以私信
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)