【问题标题】:how do you handle a double image file when it`s edited编辑时如何处理双图像文件
【发布时间】:2020-11-10 12:08:49
【问题描述】:

当我编辑图像文件时,它会在文件夹中复制文件,有人知道如何处理吗?

控制器

**public function editHome()
{
    $config['upload_path']          = './upload/images/slide/';
    $config['allowed_types']        = 'gif|jpg|png';
    $this->load->library('upload', $config);

    //edit
    $id_home = $this->input->post('id_home1', true);
    $data['dm'] = $this->db->get_where('tb_home', ['id_home' => $id_home])->row_array();

    if (!$this->upload->do_upload('gambar_home')) {
        echo "Gagal Update";
    } else {
        $dd = array('upload_data' => $this->upload->data());
        $dm = [
            'judul_home' => $this->input->post('judul_home'),
            'gambar_home' => $dd['upload_data']['file_name'],
            'desc_home' => $this->input->post('desc_home'),
            'status_home' => $this->input->post('status_home')
        ];
        $this->db->where('id_home', $this->input->post('id_home', true))->update('tb_home', $dm);
    }
    $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert"> Berhasil Update !</div>');
    redirect('admin/content/home');
}**

【问题讨论】:

    标签: php image file codeigniter


    【解决方案1】:

    默认情况下,codeigniter 文件上传库不会替换上传的同名文件,而是使用[filename]1.jpg 保存文件。如果文件名相同,你可以替换它使用:

    $config['overwrite']            = true;  //set true to overwrite the data
    $config['upload_path']          = './upload/images/slide/';
    $config['allowed_types']        = 'gif|jpg|png';
    $this->load->library('upload', $config);
    

    【讨论】:

      猜你喜欢
      • 2021-02-07
      • 1970-01-01
      • 2015-04-15
      • 2012-12-13
      • 2014-12-16
      • 2011-05-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-27
      相关资源
      最近更新 更多