如何使用codeigniter中的form_upload更新图像数据

时间:2013-05-29 02:36:57

标签: codeigniter

如何使用图像inside编辑此数据。当我按下“提交”按钮时数据已更新,但旧图像无法随新图像更改

if($this->input->post('go_upload'))
{
validation.......




$IdPerumahan = $this->uri->segment(3);

        if ($this->form_validation->run() == TRUE)
        {
            $lokasi_file = $_FILES['userfile']['tmp_name'];
            $nama_file = $_FILES['userfile']['name'];
            $ukuran_file = $_FILES['userfile']['size'];
            $direktori_file = "./images/$nama_file";

            if (empty($lokasi_file)) 
            {
                $this->load->model('PerumahanMDL');
                $this->PerumahanMDL->SimpanUbahPerumahan($IdPerumahan); 
                redirect('PerumahanCON');

            } else
            {
                $config['upload_path'] = './images/';
                $config['allowed_types'] = 'gif|jpg|png|bmp|jpeg|png';
                $config['max_size'] = '2000';
                $config['overwrite'] = 'true';
                $config['max_width'] = '1024';
                $config['max_height'] = '768';

                $this->load->library('upload', $config);
                $this->upload->initialize($config);

                $field_name = "userfile";
                if(!$this->upload->do_upload("userfile"))
                { 
                    $data['data']= 'TambahPerumahanVW';
                    $this->load->view('Desain2',$data);

                }else
                {

                            $asdf = $this->upload->data();
                            $config = array(
                                'source_image' => $asdf['full_path'],
                                'new_image' => './images/thumb',
                                'maintain_ration' => true,

                                'width' => 180,
                                'height' => 120
                        );
                        $this->load->library('image_lib', $config);
                        $this->image_lib->resize();

                        $userfile = $_FILES['userfile']['name'];    
                        $this->load->model('PerumahanMDL');
                        $this->PerumahanMDL->UbahDataPerumahan($userfile,$IdPerumahan); 

                        redirect('PerumahanCON');

                }
            }

        }
        }
}

1 个答案:

答案 0 :(得分:0)

添加overwrite = true

$this->load->library('upload', $config);
$this->upload->overwrite = true;
相关问题