我想使用Codeigniter更新数据图像

发布于 2025-02-07 01:45:23 字数 1942 浏览 3 评论 0原文

严重性:通知

消息:尝试获取非对象

文件名的属性'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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七颜 2025-02-14 01:45:23

您可以尝试使用此

 if (is_readable($gambar)) {
            $media_files = $gamba;
            $this->load->library('upload');

            // Get file data
            $type = explode("/", $gamba['type']);
            $cMediaType = $type[0];
            $cMediaName = $gamba['name'];
}

控制器代码

You can try with this

 if (is_readable($gambar)) {
            $media_files = $gamba;
            $this->load->library('upload');

            // Get file data
            $type = explode("/", $gamba['type']);
            $cMediaType = $type[0];
            $cMediaName = $gamba['name'];
}

Your controller Code

薄荷梦 2025-02-14 01:45:23

更改此行的代码:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文