Php 如何仅使用CodeIgniter上载图像文件?

Php 如何仅使用CodeIgniter上载图像文件?,php,codeigniter,Php,Codeigniter,您好,我正在尝试使用code igniter仅上载图像文件。我只需要上载png、jpg、jpeg文件。但也上载了其他类型的文件,如.txt、.mp3等。下面给出了我的代码。请立即帮助我解决此问题。提前感谢大家 $config['upload_path'] = './avatar/'; $config['allowed_types'] = 'gif|jpeg|png|jpg'; $config['max_size'] = '1024mb'; $config['max

您好,我正在尝试使用code igniter仅上载图像文件。我只需要上载png、jpg、jpeg文件。但也上载了其他类型的文件,如.txt、.mp3等。下面给出了我的代码。请立即帮助我解决此问题。提前感谢大家

    $config['upload_path'] = './avatar/';
    $config['allowed_types'] = 'gif|jpeg|png|jpg';
    $config['max_size'] = '1024mb';
    $config['max_width'] = '3000';
    $config['max_height'] = '3000';
    $this->load->library('upload', $config);

    if (!$this->upload->do_upload()) {

        $ve['data'] = $this->upload->display_errors();
    } else {
        $this->upload->data();
    } 

我认为您需要发送用户文件/上传的文件,同时尝试在if条件下验证它

if ( ! $this->upload->do_upload('userfile'))
{
    $error = array('error' => $this->upload->display_errors());
    $this->load->view('upload_form', $error);
}
else
{
    $this->upload->data();
}
if ( ! $this->upload->do_upload('userfile'))
{
    $error = array('error' => $this->upload->display_errors());
    $this->load->view('upload_form', $error);
}
else
{
    $this->upload->data();
}