【发布时间】:2015-07-24 17:16:19
【问题描述】:
我有下面的代码来上传用户图像,我的代码运行良好,但在检查 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 的相同问题
【问题讨论】:
-
您正在加载库两次。如果删除顶行会发生什么?
-
您是否也尝试过删除“set_allowed_types()”调用?
-
@Craig 在第二个我已经将 $config 数组传递给库....实际上我希望用户要上传的文件必须来自允许的类型..我删除 set_allowed_types() 但不工作
标签: php codeigniter image-uploading