codeigniter照片上传非允许类型文件没有错误警告

时间:2012-02-24 19:52:03

标签: php codeigniter upload photo

这是上传功能:

    $config['upload_path'] = './photos/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size']  = 1024 * 2;
    $config['encrypt_name'] = true;

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

    if (!$this->upload->do_upload("photo_data"))
    {
        $this->error = true;
        $this->response = $this->upload->display_errors('', '');
    }
    else
    {
        $this->upload->data();
        $this->response = "Photo successfully changed.";
    }

    $array = array(
        'error' => $this->error,
        'response' => $this->response
    );

    return $array;

然而,为了测试它不允许文件类型,除了我允许我将视频重命名为.jpg并试图上传它...

它没有继续,但它也没有发送错误消息...我想在upload class returns false中的某个地方...任何想法如何确保它首先向用户发送消息?

1 个答案:

答案 0 :(得分:0)

您如何在视图中打印错误?在上传类中某处返回false的方法是您已检查过FALSE的方法,即$this->upload->do_upload()

如果您希望网站显示这些错误,您应该将这些错误传递给视图:

这假定您发布的代码来自控制器:

$array = array(
        'error' => $this->error,
        'response' => $this->response
    );

$this->load->view('upload_view',$array);
//instead of returning, as "return" in a controller makes little sense. If you're inside a model, then, get the returned value in a controller and pass it to a view. 

在你的" upload_view.php"查看文件:

<div class="<?php $error? 'error' : 'success';?>"><?php echo $response;?></div>