文章编辑中有个缩略图需要上传,修改时需要更换图片,这是就要判断是否有新的图片上传上来。
@$tempuserfile = $_FILES['userfile']['tmp_name'];
if (!empty($tempuserfile)){
$config['upload_path'] = './../upload/images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '0';
$config['max_width'] = '0';
$config['max_height'] = '0';
$config['encrypt_name'] = true;
$this->load->library('upload', $config);
if (!$this->upload->do_upload()){
$this->db->where('id',$this->uri->segment(3),1);
$data['query'] = $this->db->get('actives');
$data['error'] = $this->upload->display_errors();
$this->load->view('editActive_view', $data);
}else{
$data = array('image_data' => $this->upload->data());
$updateData['image'] = "/upload/images/".$data['image_data']['file_name'];
}
}
$updateData['title'] = $_POST['title'];
$updateData['type'] = $_POST['type'];
$updateData['body'] = $_POST['body'];
$this->db->where('id',$this->uri->segment(3),1);
$this->db->update('actives',$updateData);
redirect('main/manageActive');

写得很不错,多谢分享喽。欢迎回访