Codeigniter图像上载忽略允许的类型和文件大小

时间:2015-05-13 12:14:14

标签: php codeigniter image-uploading

我有以下代码上传用户图片,我的代码工作正常但我在检查allowed_types时遇到问题,即png|jpgmax_size .. 它不会检查允许的类型最大尺寸

代码:

$this->load->library('upload');
$config['upload_path'] = 'admin/upload/';
$config['allowed_types'] = 'jpg|jpeg';
$config['max_size'] = '100';

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

if (!$this->upload->do_upload('user_image')){ 
    $data = array('msg' => $this->upload->display_errors());
    $flag="1";
}else { 
    $image_path = $this->upload->data();
    $flag="2";
}

输出:

$flag始终设置为2 ...即使我上传了文件.png或.gif也存在同样问题max_size

1 个答案:

答案 0 :(得分:3)

尝试增加max_size。同时删除行$ this-> upload-> set_allowed_types('*');