我有以下代码上传用户图片,我的代码工作正常但我在检查allowed_types
时遇到问题,即png|jpg
和max_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
答案 0 :(得分:3)
尝试增加max_size。同时删除行$ this-> upload-> set_allowed_types('*');