2011-03-04 9 views
0

안녕하세요, 이미지 업로드 모듈을 어디에 이미지 경로를 데이터베이스에 저장하고 미리보기에서 검색 모듈을 개발하겠습니다. 편집하고 업데이트하고 싶지만 내 문제는 삭제되지 않습니다. 오래된 이미지이지만 새 이미지를 저장하고 업데이트합니다.codeigniter 업데이트 이미지 업로드

당신이 나에게 좋은 튜토리얼 기본 추가, 편집 - 업데이트 삭제 이미지 업로드 어디 DB에 이미지를 저장하시기 바랍니다 바란다. 감사! 당신은 당신이 unlink은 (삭제) 데이터베이스에서 이전 이미지의 경로를로드해야합니다 이전 파일을 옛 아바타 파일을 덮어 쓸 때 다음과

다음, 프로필 컨트롤러

<?php 
      function edit_profile() 
      { 
       $id=$this->uri->segment(3); 
       $this->load->model('profile_model');  
       $this->load->library('form_validation'); 
      // field name, error message, validation rules 
      $this->form_validation->set_rules('name', 'Name', 'trim|required'); 
      $this->form_validation->set_rules('city', 'City', 'trim|required'); 
      $this->form_validation->set_rules('telno', 'Tel no.', 'trim|required'); 

       if ($this->form_validation->run() == FALSE) 
       { 
       if(empty($id)) $id=$this->input->post('id'); 

       $data['result'] = $this->profile_model->profile_hotel($id); 
       $data['id']=$id; 
       $this->load->view('profile/edit_form', $data); 
       } 
       else{ 
      if(isset($_FILES['profile_avatar'])) 
      { 
       $this->load->model('profile_model'); 
       $file = read_file($_FILES['upload']['tmp_name']); 
       $profile_avatar = basename($_FILES['upload']['name']); 

       write_file('files/'.$profile_avatar, $file); 

       $this->profile_model->update_profile($profile_avatar); 
      } 
       }  
      } 

/* My update function in profile_model */ 

    function update_profile($profile_field) 
    { 
    if(!empty($profile_field)){ 
     $profile_avatar = $this->input->post('profile_avatar'); 
    } 
    else{ 
     $profile_avatar = $profile_field; 
    } 
     $id = $this->input->post('id'); 
     $new_profile_update_data = array( 
     'name' => $this->input->post('name'), 
     'city' => $this->input->post('city'), 
     'telno' => $this->input->post('telno'), 
     'avatar' => $profile_avatar, 
    ); 
     $this->db->where('id', $id); 
     $this->db->update('tbl_profile', $new_profile_update_data); 
    } 

?> 

/*My profile edit view*/ 

<?php 

    echo form_open_multipart('profile/edit_profile').'<br/>'; 
    $fetch=$result->row(); 
?> 
<img width="200" height="200" src="<?php echo base_url()?>files/<?php echo $fetch->hotel_logo;?>"><br/> 
<?php 

    echo form_hidden('id',$id); 
    echo form_hidden('profile_avatar', $fetch->profile_avatar).'<br/>';  
    echo '<span>avatar</span>'; 
    echo '<input type="file" name="profile_avatar" />'.'<br/>'; 
    echo form_input('name', $fetch->name).form_error('name').'<br/>'; 
    echo form_input('city', $fetch->city) .form_error ('city').'<br/>'; 
    echo form_input('telno', $fetch->telno).form_error ('telno').'<br/>'; 

    echo form_submit('submit', 'Save'); 
    ?> 
    <?php echo validation_errors('<p class="errors">');?> 
+0

없는 코드, 아니 대답 할 수 있어야한다! 보여! –

+0

@Carlos Mora 이미 내 코드를 추가합니다. 덕분에 저를 도울 수 있기를 바랍니다. – Dave

답변

0

내 편집이다 새 파일을 쓰고 마지막으로 새 파일의 경로를 데이터베이스에 씁니다.

0

데이브 : 모델에

보기 : '!'나는이 생각

if (!empty($profile_field)) { 
    $profile_avatar = $this->input->post('profile_avatar'); 
} else { 
    $profile_avatar = $profile_field; 
} 

그건 틀렸다. 그것은

if (empty($profile_field)) { 
    $profile_avatar = $this->input->post('profile_avatar'); 
} else { 
    $profile_avatar = $profile_field; 
} 

이가 실수

관련 문제