2014-01-13 4 views
0

저는 프로젝트를 위해 CodeIgniter를 사용하는 데 2-3 주가 걸렸습니다. (너무 부드럽게하십시오.) 이미지를 업로드하는 데 어려움을 겪고 있습니다. 나는 Uploads 폴더를 루트 폴더에두고 다음 코드를 가지고 있습니다.Codeigniter 이미지 업로드

더 좋든 나 나쁘 든이 기능 구현과 동시에 시도하고 배우기 위해 자습서를 수행했습니다.

컨트롤러 :

public function upload(){ 

     $config['upload_path'] = "/uploads"; 
     $config['allowed_types'] = "jpg|jpeg|gif|png|bmp"; 
     $this->load->library('upload', $config); 

     if($this->upload->do_upload()){ 

      echo "it worked"; 

      $finfo=$this->upload->data(); 
      $this->_createThumbnail($finfo['file_name']); 
      $data['uploadInfo'] = $finfo; 
      $data['thumbnail_name'] = $finfo['raw_name']. '_thumb' .$finfo['file_ext']; 
      $this->load->view('project_success'); 

     } else {echo "it didn't work";} // This is what I end up getting 

    } 

    public function _createThumbnail($filename){ 

     $config['image_library'] = "gd2";  
     $config['source_image']  = "/uploads" .$filename;  
     $config['create_thumb']  = TRUE;  
     $config['maintain_ratio'] = TRUE;  
     $config['width'] = "120";  
     $config['height'] = "80"; 
     $this->load->library('image_lib',$config); 
    } 

}

보기 :

<?php echo form_open_multipart('build/upload');?> 
<div class="row"> 
    <div class="large-12 columns"> 
     <span class="number left">3</span> 
     <h3>Project Images</h3> 
    </div> 
    <div class="large-1 columns"></div> 
    <div class="large-10 large-centered columns"> 
     <div class="row"> 
      <div class="large-8 columns"> 
        <label for="file">Add Images...</label> 
        <input type="file" name="file" id="file"><br> 
        <input class="button secondary radius wide right" type="submit" name="submit" value="Submit"> 
       <br/> 

      </div> 
     </div> 
    </div> 
    <div class="large-1 columns"></div> 
</div> 

<br/><br/> 

이들은 전체가 아닌 - I가 관련했다 코드의 부분 만 포함하도록 시도 내 문제. 전체보기 및 컨트롤러에서 알려 주시면 알려주세요.

누구나 도움/조언을 제공합니까? 나는 매우 감사 할 것이다!

+0

error_log를 확인 했습니까? 업로드 폴더에 대한 사용 권한만큼 간단 할 수 있습니다. –

+0

터미널 (777)에서 폴더 사용 권한을 변경했습니다 – user2653658

+0

'else'조건에서'display_errors()'함수를 사용합니다 –

답변

0

는 값을 볼 수 var_dump($imgUpload1['upload_data1']); 쓰기 대신 $finfo=$this->upload->data();

$this->upload->do_upload('file');

$imgUpload1 = array('upload_data1' => $this->upload->data()); 

보십시오.

작동하는지 알려주세요.

+0

그냥 NULL을 말합니다 – user2653658

+0

업로드 할 trait하고있는 이미지가 업로드되었는지 확인하십시오. 그렇지 않은 경우 실수로 폴더에 액세스 할 수 없기 때문일 수 있습니다. 즉, do_upload() 함수는 프로젝트에 이미지를 업로드하고 upload-> data()는 업로드 된 이미지에 대한 모든 데이터를 가져옵니다. 이제 무언가를 해보십시오. 응용 프로그램 폴더가 아닌 프로젝트에서 새 폴더 호출 내용을 만듭니다. 따라서 세 개의 폴더, 응용 프로그램, 콘텐츠 및 시스템을 갖게됩니다. 그런 다음 $ config [ 'upload_path'] = 'content';를 작성하십시오. 당신이 가지고있는 것을 대체하십시오. 다시 시도하십시오 !!! –

관련 문제