Codeigniter更换已经上传图片

上传

文章编辑中有个缩略图需要上传,修改时需要更换图片,这是就要判断是否有新的图片上传上来。

@$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');

 

除非注明, 风波竹林 文章均为原创,转载请以链接形式标明本文地址
本文地址: https://blog.fbzl.org/codeigniter更换已经上传图片/
Codeigniter更换已经上传图片” 有 1 条评论

发表回复