如何解决CodeIgniter图片上传-无法获得错误消息以显示
| 这是我的上传模型 function upload_avatar()
{
$id = $this->tank_auth->get_user_id();
//config upload parameters and upload image
$config = array(
\'allowed_types\' => \'jpeg|jpg|png\',\'upload_path\' => $this->upload_path,\'max_size\' => 2048,\'encrypt_name\' => TRUE,\'overwrite\' => FALSE,);
$this->load->library(\'upload\',$config);
$this->upload->do_upload();
//get upload data,config,resize uploaded image,save in avatars subfolder
$image_data = $this->upload->data();
if ($image_data[\'file_size\'] < 2048) {
$config = array(
\'source_image\' => $image_data[\'full_path\'],\'new_image\' => $this->upload_path . \'/avatars\',\'maintain_ratio\' => TRUE,\'width\' => 125,\'height\' => 125
);
$this->load->library(\'image_lib\',$config);
$this->image_lib->resize();
//only burn avatar path to user_profiles table if no upload errors
if (!$this->upload->display_errors()) {
$data = array(\'avatar\' => base_url() . \'images/avatars/\' . $image_data[\'file_name\']);
$this->db->where(\'id\',$id);
$this->db->update(\'user_profiles\',$data);
}
//delete the original file from server
$this->load->helper(\'file\');
unlink($image_data[\'full_path\']);
} else {
echo $this->upload->display_errors();
}
}
尝试上传大于2MB的文件时,我无法收到错误消息直接向浏览器回显。
公平地说,CI会忽略此大文件,并且当文件<2MB时正确上传。
唯一的是,我无法获得错误消息以显示在前端以向suer提供一些反馈。
有什么主意吗?解决方法
$config[\'upload_path\'] = \'uploads/category/\'.$id.\'/\';
//echo $file_name;die;
//echo $config[\'upload_path\'];
$config[\'allowed_types\'] = \'gif|jpg|jpeg|png\';
$config[\'max_size\'] = \'2048\';
$config[\'max_width\'] = \'1920\';
$config[\'max_height\'] = \'1280\';
$this->load->library(\'upload\');
foreach ($_FILES as $key => $value) {
//print_r($key);
if (!empty($key[\'name\'])) {
$this->upload->initialize($config);
if (!$this->upload->do_upload($key)) {
// echo \'test\';die;
// rmdir(\'uploads/category/\'.$id);
$errors = $this->upload->display_errors();
flashMsg($errors);
}
}
}
尝试这个!!,您的post_max_size
限额是否少于2MB? (http://ca3.php.net/manual/zh/ini.core.php#ini.post-max-size)如果这样,则在调用代码之前,该文件可能已被丢弃。
更新:
如果您在else块中取出函数调用,然后放入exit(\'too big \');那你能看到错误吗?如果是这样,可能是您如何取消通话。版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。