我被卡住了從codeigniter更新圖像,我想要替換圖像時,我更新它但代碼其不起作用。 這裏是我的代碼:更新codeigniter上的圖像
這是控制器:
public function updatefoto(){
$this->load->model('model_users');
$this->model_users->updatefoto();
}
這是模型
public function updatefoto($userId){
if($this->input->post('submit')){
$config['upload_path'] = "./uploads/images/";
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '2000';
$config['max_width'] = '2000';
$config['max_height'] = '2000';
$config['file_name'] = 'gambar-'.trim(str_replace(" ","",date('dmYHis')));
$this->load->library('upload', $config);
if (!$this->upload->do_upload("gambar")) {
$error = array('error' => $this->upload->display_errors('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>','</div>'));
$this->load->view('view_ubah_data-profile', $error);
}else{
$nama=$this->upload->data('file_name');
$this->db->where('id', $userId);
$this->db->update('foto',array('nama_foto'=>$nama));
redirect('view_ubah_data-profile','refresh');
}
}
}
,最後是視圖
<div class="col-md-4 col-sm-6 col-xs-12">
<form action="users/updatefoto" method="post" id="updateUserImage">
<div class="text-center">
<img src="<?php echo base_url();?>uploads/images/<?php echo $userData['nama_foto'] ?>" cclass="img-thumbnail" alt="avatar">
<h6>Upload a different photo...</h6>
<input type="file" class="text-center center-block well well-sm" name="gambar" id="files" accept="image/*" required>
<button type="submit" value="Upload" name="submit" class="btn btn-primary">
<i class="fa fa-upload" aria-hidden="true"></i>upload
</button>
</div>
</form>
</div>
謝謝,我感謝所有幫助:)
更新在控制器中的圖像不在模型 –
請遵循https://www.codeigniter.com/ userguide3/libraries/file_uploading.html –
@MalikMudassar我想更新圖片不插入/上傳圖片/ – Firm