首页 > 解决方案 > 编辑时如何处理双图像文件

问题描述

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

控制器

**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');
}**

标签: phpimagefilecodeigniter

解决方案


默认情况下,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);

推荐阅读