我想使用Codeigniter更新数据图像
严重性:通知
消息:尝试获取非对象
文件名的属性'gambar':admin/carouselController.php
行号:42
控制器
public function edit_carousel(){//update carousel
$id= $this->input->post('id_carousel');
$data = $this->modelcarousel->getDataById($id)->row();
$gambar = './assets/foto/carousel/'.$data->gambar;
if (is_readable($gambar) && unlink($gambar)) {
$config['upload_path'] = './assets/foto/carousel';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = 2048;
$config['max_width'] = 10000000;
$config['max_height'] = 10000000;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if (!$this->upload->do_upload('gambar')) {
$error = array('error' => $this->upload->display_errors());
}else{
$gambar = $this->upload->data();
$data = array(
'gambar' => $gambar,
'headline' => $this->input->post('headline'),
'deskripsi' => $this->input->post('deskripsi'),
'status' => $this->input->post('status'),
'tanggal_post' => $this->input->post('tanggal_post')
);
$update = $this->modelcarousel->update_carousel($id,$data);
if ($update) {
redirect('carousel');
}else{
echo 'Gagal';
}
}
}
}
模型
function update_carousel($id,$data){//update carausel
$this->db->where('id_carousel',$id);
return $this->db->update('tb_carousel',$data);
}
function getDataById($id){
$this->db->where('id_carousel',$id);
return $this->db->get('tb_carousel');
}
数据库: id_carousel 甘巴 标题 Deskripsi 地位 tanggal_post
Severity: Notice
Message: Trying to get property 'gambar' of non-object
Filename: admin/CarouselController.php
Line Number: 42
Controller
public function edit_carousel(){//update carousel
$id= $this->input->post('id_carousel');
$data = $this->modelcarousel->getDataById($id)->row();
$gambar = './assets/foto/carousel/'.$data->gambar;
if (is_readable($gambar) && unlink($gambar)) {
$config['upload_path'] = './assets/foto/carousel';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = 2048;
$config['max_width'] = 10000000;
$config['max_height'] = 10000000;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if (!$this->upload->do_upload('gambar')) {
$error = array('error' => $this->upload->display_errors());
}else{
$gambar = $this->upload->data();
$data = array(
'gambar' => $gambar,
'headline' => $this->input->post('headline'),
'deskripsi' => $this->input->post('deskripsi'),
'status' => $this->input->post('status'),
'tanggal_post' => $this->input->post('tanggal_post')
);
$update = $this->modelcarousel->update_carousel($id,$data);
if ($update) {
redirect('carousel');
}else{
echo 'Gagal';
}
}
}
}
Model
function update_carousel($id,$data){//update carausel
$this->db->where('id_carousel',$id);
return $this->db->update('tb_carousel',$data);
}
function getDataById($id){
$this->db->where('id_carousel',$id);
return $this->db->get('tb_carousel');
}
database:
id_carousel
gambar
headline
deskripsi
status
tanggal_post
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试使用此
控制器代码
You can try with this
Your controller Code
更改此行的代码:
$ this-> load-> library('upload',$ config);
向此(不发送第二个参数)
$ $ this-> load-> library('upload');
Change this line of code:
$this->load->library('upload', $config);
To this (do not send the second parameter)
$this->load->library('upload');