2014-10-10 3 views
0

안녕하세요, 저는 codeigniter에서 이미지를 업로드했습니다. 파일을 이미지 폴더에 저장 한 다음 데이터베이스에 저장하면 잘 실행됩니다. 내 문제는 내가 그걸로 파일을 선택하지 않으면 내 현재의 이미지가 유지됩니다 원인이 프로필 편집 페이지입니다. 모든 텍스트 상자에 대한 유효성을 설정하지 않습니다. 이미지 업로드에만 사용됩니다. .doc .exe .flv와 같은 비 이미지 유형을 업로드하려고하거나 이미지가 아닌 경우 "업로드를 시도하는 파일 형식이 허용되지 않습니다." 그리고 나는 그것이 현재 이미지를 유지할 이미지를 바꾸지 않을 때 그것을 원한다. 여기에 코드 줄에codeigniter에서 파일을 선택하지 않고 이미지를 업로드

$config['upload_path'] = 'assets/uploads/'; 
     // set the filter image types 
     $config['allowed_types'] = 'gif|jpg|png'; 
     $config['max_size'] = '9000'; 
     $config['encrypt_name'] = TRUE; 

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

     $this->upload->initialize($config); 
     $this->upload->set_allowed_types($config['allowed_types']); 
     $data['upload_data'] = ''; 

     //if not successful, set the error message 
     if (!$this->upload->do_upload('photo')) { 
     $data = $this->upload->display_errors(); 

     $this->session->set_flashdata('error', 1); 
     redirect('profile/edit/id/'.$ids, $data); 

     }else{ //else, set the success message   
     $data['upload_data'] = $this->upload->data(); 

     $uploadSuccess = $data['upload_data']; 

     $raw_name = $uploadSuccess['file_name']; 

     $file_name = $raw_name; 
     //print_r($file_name);exit; 
     $image_path = 'assets/uploads/' .$file_name; 
     $config['image_library'] = 'gd2'; 
     $config['source_image'] = $image_path; 
     $config['create_thumb'] = TRUE; 
     $config['maintain_ratio'] = TRUE; 
     $config['width'] = 150; 
     $config['height'] = 110; 
     //$config['quality'] = '80%'; 

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

     $this->image_lib->resize($image_path); 
     $this->image_lib->clear(); 
     } 

아래에있는 내 코드

!$this->upload->do_upload('photo') 

때 너무이 코드 라인의 유효성을 검사하는 비 이미지를 업로드 메신저. 및

$data = $this->upload->display_errors(); 

내보기

<?php if($this->session->flashdata('error')): ?> 
      <div class="alert alert-success"> 
      <button class="close" data-dismiss="alert" type="button">×</button> 
      <p >The filetype you are attempting to upload is not allowed.</p> 
      </div> 
     <?php endif; ?> 

나는 메신저 내 편집 페이지에서 내 curent 사진을 보관하는 파일을 선택하지 않을 경우 누군가가 나에게이 일을 알아 냈 도울 수 원하는 작동합니다 ?? 어떤 도움이라도 대단히 감사합니다. 이미지 코드를 업로드하기 전에

답변

0

을 보내 주셔서 감사합니다. 또는 이미지 업로드를위한 기능을 사용하고 있다면 조건을 설정해야합니다. 이미지를 사용할 수 있으면 해당 코드를 실행해야합니다. 예 :

if(isset($_FILES['photo']['name'])){ 
    // image upload code here or call upload function 
} 

이 정보는 도움이 될 수 있습니다.

+0

내 코드에 이것을 추가 할 예정입니까 ?? – hello

+0

당신의 생각을 넓힐 수 있습니까? – hello

+0

그 수표를 추가 했습니까? 당신이 양식을 제출할 때 이미지를 선택했는지 여부, 이미지 업로드 코드가 실행 된 것 같아요.이 조건은 이미지 존재 여부를 확인한 다음 이미지 업로드 코드가 건너 뛰면 건너 뜁니다. 왜냐하면 이미지가 선택되지 않았을 때 코드는 기존 이미지를 폴더가 아닌 db의 빈 이미지로 대체하기 때문에 편집시 데이터베이스와 폴더 모두에서 해당 이미지를 삭제해야합니다. –

관련 문제