Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //===============================================
  2.     function edit(){
  3.         $config = array(
  4.                         'upload_path'=>'./uploads',
  5.                         'allowed_types'=>'jpg|png|jpeg',
  6.                         'max_size'=>2086
  7.                         );
  8.        
  9.         $id = $this->input->post('id');
  10.         $judul = $this->input->post('judul');
  11.         $tebal = $this->input->post('tebal');
  12.         $penerbit = $this->input->post('penerbit');
  13.         $data_kode = array('id'=>$id);
  14.         $foto = $this->db->get_where('tb_buku',$data_kode);
  15.    
  16.     if($foto->num_rows()>0){
  17.       $pros=$foto->row();
  18.       $name=$pros->gambar;
  19.      
  20.       if(file_exists($lok=FCPATH.'/uploads/'.$name)){
  21.         unlink($lok);
  22.       }
  23.       if(file_exists($lok=FCPATH.'/uploads/thumbnail/'.$name)){
  24.         unlink($lok);
  25.       }}
  26.  
  27.         $this->load->library('upload',$config);
  28.        
  29.         if($this->upload->do_upload('gambar')){
  30.  
  31.         $finfo = $this->upload->data();
  32.         $nama_foto = $finfo['file_name'];
  33.  
  34.         $data_buku = array(
  35.                             'judul'=>$judul,
  36.                             'tebal'=>$tebal,
  37.                             'penerbit'=>$penerbit,
  38.                             'gambar'=>$nama_foto
  39.                             );
  40.  
  41.         $config2 = array(
  42.                 'source_image'=>'uploads/'.$nama_foto,
  43.                 'image_library'=>'gd2',
  44.                 'new_image'=>'uploads/thumbnail',
  45.                 'maintain_ratio'=>true,
  46.                 'width'=>150,
  47.                 'height'=>200
  48.             );
  49.        
  50.         $this->load->library('image_lib',$config2);
  51.         $this->image_lib->resize();    
  52.        
  53.         }else{
  54.         $data_buku = array(
  55.                             'judul'=>$judul,
  56.                             'tebal'=>$tebal,
  57.                             'penerbit'=>$penerbit
  58.                             );
  59.  
  60.         }
  61.        
  62.         $this->M_buku->edit_data($data_kode,$data_buku);
  63.         redirect('C_buku');
  64.     }