2017-02-16 1 views
1

이미지 업데이트 중 문제가 발생했습니다. 잘 작동하는 이미지 업로드를 만들었지 만 업데이트되기를 원합니다. 필요한 이미지를 추가 할 때 올바르게 업데이트되지만 이미지를 변경하지 않고 그대로두면 현재 이미지를 검색 할 수 없습니다. 나를Codeigniter : 이미지 및 디스플레이 업데이트

컨트롤러

public function insert() 
     { 
     $data['s_em']=$this->input->post('s_em'); 
     $data['s_na']=$this->input->post('s_na'); 
    $config['upload_path'] = './uploads/'; 
     $config['allowed_types'] = 'gif|jpg|png|jpeg|jpe|pdf|doc|docx|rtf|text|txt'; 
      $this->load->library('upload', $config); 
            if (! $this->upload->do_upload('file')) 
             { 
           $error = array('error' => $this->upload->display_errors()); 

             } 

          else 
           { 

         $data['file']=$this->upload->data('file_name'); 


       } 

       $this->Students_m->db_ins($data); 


     $this->load->view('admin/newstudents'); 


    } 

    public function edit($id) 
    { 
     $dt['da']=$this->Students_m->db_edit($id)->row_array(); 
     $this->load->view('admin/st_edt',$dt); 
     } 

public function update() 
{ 
    $id=$this->input->post("id"); 

    $s_em=$this->input->post("s_em"); 
    $s_na=$this->input->post("s_na"); 

    $config['upload_path'] = './uploads/'; 
    $config['allowed_types'] =  'gif|jpg|png|jpeg|jpe|pdf|doc|docx|rtf|text|txt'; 
    $this->load->library('upload', $config); 
    if (! $this->upload->do_upload('file')) 
    { 
     $error = array('error' => $this->upload- >display_errors()); 
    } 
    else 
    { 
     $upload_data=$this->upload->data(); 
     $image_name=$upload_data['file_name']; 
    } 

$data=array('s_em'=>$s_em,'s_na'=>$s_na,'file'=>$image_name); 
$this->Students_m->db_update($data,$id); 
} 

redirect("admin/students"); 
} 

모델

public function db_ins($data) 
    { 
    $query=$this->db->insert('student',$data); 
    return $query; 
    } 
public function db_edit($id) 
{ 
    return $this->db->get_where('student', array('id'=>$id)); 
} 
public function db_update($data,$id) 
{ 
    $this->db->where('id', $id);  
    $this->db->update('student', $data); 
} 

보기 도와주세요

<form action="../update" method="post" enctype="multipart/form-data"> 

    <legend class="text-semibold">Personal data</legend> 
    <img src=" <?php echo base_url('uploads/'. $da['file']);?>" height="205" width="205"> 

           <div class="row"> 
             <div class="col-md-6"> 
              <div class="form-group"> 
             <label class="display-block">image:<span class="text-danger">*</span></label> 
             <input name="file" type="file" id="image_id" class="file-styled "> 
             <span class="help-block"></span> 
            </div> 
           </div> 
        <div class="col-md-6"> 
            <div class="form-group"> 
             <label>Email address: <span class="text-danger">*</span></label> 
             <input type="email" name="s_em" class="form-control required" value="<?php echo $da['s_em'];?>"> 
            </div> 
           </div> 
          </div> 
          <div class="row"> 

          <div class="col-md-6"> 
            <div class="form-group"> 
             <label>Student name: <span class="text-danger">*</span></label> 
             <input type="text" name="s_na" class="form-control required" value="<?php echo $da['s_na'];?>" id="n1"> 
            </div> 
           </div> 
          <button type="submit">Update<i class="icon-check position-right"></i></button> 
        <input type="hidden" name="id" value="<?php echo $da['id'] ;?>"> 
        </form> 
       </div>          
+0

보기 페이지를 추가 할 수 있습니까? – Vimal

+0

** 예 ** @ vimal s – anu

+0

파일을 폴더로 이동하고 있습니까? right..i 업로드 코드를받지 못했습니다. – Vimal

답변

0
public function update() 
    { 
     $id=$this->input->post("id"); 

     $s_em=$this->input->post("s_em"); 
     $s_na=$this->input->post("s_na"); 


if($_FILES[file]['name']!="") 
      { 
    $config['upload_path'] = './uploads/'; 
     $config['allowed_types'] =  'gif|jpg|png|jpeg|jpe|pdf|doc|docx|rtf|text|txt'; 
     $this->load->library('upload', $config); 
     if (! $this->upload->do_upload('file')) 
     { 
      $error = array('error' => $this->upload- >display_errors()); 
     } 
     else 
     { 
      $upload_data=$this->upload->data(); 
      $image_name=$upload_data['file_name']; 
     } 
    } 
    else{ 
       $image_name=$this->input->post('old'); 
      } 
$data=array('s_em'=>$s_em,'s_na'=>$s_na,'file'=>$image_name); 
$this->Students_m->db_update($data,$id); 
} 

첫 번째 서버에 성공적으로 업데이트됩니다.

+0

편집 ... 귀하의 업데이트 기능을 .. .. – Vimal

+0

감사합니다 vimal .. 작업 .. Logged – anu

0

당신이 동일한 이름을 가진 이미지를 업로드 할 때 항상주의해야합니다. 성공적으로 업로드되었지만 프런트 엔드에서 변경된 URL이 보이지 않으면 브라우저에서 이전 이미지를 캐시했기 때문에 URL과 이름이 같습니다.

확인 이미지를 확인은 다음

<input type="hidden" id="old" name="old" value="<?php echo $da['file'] ?>"> 

날이 작동 여부를 알 수 this..let 시도 추가 뷰 파일에서

관련 문제