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条)

报告相同问题?

悬赏问题

  • ¥30 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目
  • ¥15 数电几道习题,写出作答过程,ai一律不采用
  • ¥15 利用pthon计算薄膜结构的光导纳
  • ¥15 海康hlss视频流怎么播放
  • ¥15 Paddleocr:out of memory error on GPU
  • ¥30 51单片机C语言数码管驱动单片机为AT89C52