【发布时间】:2018-10-29 18:11:55
【问题描述】:
最近我在一次更新两个图像时发现了一些错误。我在第一张图片之前使用if (!empty($_FILES['ngo_logo']['name'])),在第二张图片之前使用elseif (!empty($_FILES['ngo_license_pic']['name']))。
这是我的完整控制器代码:
function editProfile(){
$ngo_id = $this->profile_model->editNgoProfile();
/************* File Upload ************/
if (!empty($_FILES['ngo_logo']['name'])) {
$config['upload_path'] = './assets/uploads/ngo_logo/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|pdf|doc|docx|zip|xls';
$config['overwrite'] = true;
$config['remove_spaces']=true;
$config['max_size']='10600';// in KB
$this->load->library('upload', $config);
$filetype = $_FILES['ngo_logo']['type'];
$file_name = $_FILES['ngo_logo']['name'];
if($filetype == "image/jpg")
$file_type='jpg';
else if ($filetype == "image/jpeg")
$file_type='jpeg';
else if ($filetype == "image/gif")
$file_type='gif';
else if($filetype == "image/jpeg")
$file_type='jpg';
else if($filetype == "image/pjpeg")
$file_type='pjpeg';
else if($filetype == "image/png")
$file_type='png';
$_FILES['ngo_logo']['name']=$ngo_id.'.'.$file_type;
$this->upload->do_upload('ngo_logo');
$up_dtat = array('ngo_logo' => $_FILES['ngo_logo']['name']);
$this->db->where('ngo_id',$ngo_id);
$this->db->update('tbl_ngo_users',$up_dtat);
}
elseif (!empty($_FILES['ngo_license_pic']['name'])) {
$config['upload_path'] = './assets/uploads/ngo_license_pic/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|pdf|doc|docx|zip|xls';
$config['overwrite'] = true;
$config['remove_spaces']=true;
$config['max_size']='10600';// in KB
$this->load->library('upload', $config);
$filetype = $_FILES['ngo_license_pic']['type'];
$file_name = $_FILES['ngo_license_pic']['name'];
if($filetype == "image/jpg")
$file_type='jpg';
else if ($filetype == "image/jpeg")
$file_type='jpeg';
else if ($filetype == "image/gif")
$file_type='gif';
else if($filetype == "image/jpeg")
$file_type='jpg';
else if($filetype == "image/pjpeg")
$file_type='pjpeg';
else if($filetype == "image/png")
$file_type='png';
$_FILES['ngo_license_pic']['name']=$ngo_id.'.'.$file_type;
$this->upload->do_upload('ngo_license_pic');
$up_dtat = array('ngo_license_pic' => $_FILES['ngo_license_pic']['name']);
$this->db->where('ngo_id',$ngo_id);
$this->db->update('tbl_ngo_users',$up_dtat);
}
redirect('NGO_Profile');
}
我的问题是只有第一张图片会更新,而另一张不会更新。
--> 如果我只上传一张图片,那么它会更新并
--> 如果我只上传第一张图片,那么第一张图片更新
--> 以后如果我只上传第二张图片,那么第二张图片将只更新...
我需要正确的解决方案,实际上不一次更新两个图像的主要原因是什么。
【问题讨论】:
标签: php codeigniter image-uploading