2012-02-06 4 views
0

$ this-> load-> library ('upload')에 문제가 있습니다. 내가 컨트롤러에서 그것을 호출하면 잘 작동하지만 모델에 넣을 때 "개체가 아닌 객체에서 do_upload() 멤버 함수 호출"오류가 발생합니다.모델에서 호출 할 때 Codeigniter가 라이브러리 업로드를로드 할 수 없습니다.

여기 내 업로드 코드가 있습니다. 대부분의 코드

function upload_file_model(){ 
    if(isset($_FILES['upPhoto'])){ 
     $upMsg = ""; 
     $uploadPath; 
     $uploadDirectory; 
     $this->uploadPath = realpath(APPPATH . DIRECTORY_SEPARATOR . "root"); 
     $this->uploadDirectory = $this->input->post('txt_current_directory'); 
     $this->uploadDirectory = explode("/", $this->uploadDirectory); 
     $this->uploadDirectory = implode(DIRECTORY_SEPARATOR, $this->uploadDirectory); 
     $this->upload = $this->uploadPath . DIRECTORY_SEPARATOR . $this->uploadDirectory; 

     for($i = 0;$i<count($_FILES['upPhoto']['name']);$i++){ 
      $_FILES['userfile']['name'] = $_FILES['upPhoto']['name'][$i]; 
      $_FILES['userfile']['type'] = $_FILES['upPhoto']['type'][$i]; 
      $_FILES['userfile']['tmp_name'] = $_FILES['upPhoto']['tmp_name'][$i]; 
      $_FILES['userfile']['error'] = $_FILES['upPhoto']['error'][$i]; 
      $_FILES['userfile']['size'] = $_FILES['upPhoto']['size'][$i]; 
      $config = array(
       'upload_path' => $this->upload, 
       'allowed_types' => 'gif|jpg|png|jpeg|doc|csv', 
       'max_size' => '10000', 
       'max_width' => '10000', 
       'max_height' => '10000', 
       'overwrite' => false, 
       'file_name' => 'test_' + $i 
      ); 

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

      if($this->upload->do_upload()){ 
       $this->upMsg .= $_FILES['upPhoto']['name'][$i] . " Uploaded. <br>"; 
      }else{ 
       $this->upMsg .= $_FILES['upPhoto']['name'][$i] . " was not Uploaded. <br> . ERROR : " . $this->upload->display_errors(); 
      } 
     } 
     // echo $this->upMsg; 
     $this->status = TRUE; 
     $this->msg = $this->upMsg; 
    }else{ 
     // echo "FALSE"; 
     $this->status = FALSE; 
     $this->msg = "ERROR : You did not select a file to upload."; 
    } 
    return $this->respond(); 
} 

내가 단지의 일부를 수정 phpx 에 의해이 링크 Codeigniter multiple file upload messes file extension ~에서 비롯됩니다.

get_instance(); 

그래서 당신이 (정말 아무 곳이나) 모델에서 업로드 라이브러리를로드하기 위해 다음을 수행 할 수 있습니다 : 당신이 컨트롤러 내부에 있지 않을 때

+0

왜 '$ this-> upload'를'for' 루프 앞에 문자열에 할당 했습니까? –

+0

@KemalFadillah, 어떻게 내가 이것을 놓칠 수 있 었는가! 나는 $ this-> upload를 바꿨고 효과가 있었다. 고마워, – jONGsKiE777

답변

0

당신은이 $this 개체를 가져를 사용할 수 있습니다 :

get_instance()->load->library('upload', $config); 
+0

어 ... 언제부터? 나는 그것을 보지 못했다 ... 어떤 버전인가? 또한 수퍼 객체에 대한이 참조가 모델에도 존재합니다 –

+0

음, CI 문서에서 읽었습니까? 내가 처음 들어 봤어. 너 더 설명 할 수 있니? 감사합니다 – jONGsKiE777

+0

@ jongsKiE777 당신은 컨트롤러, 모델 및 뷰에서 $가 잘 작동하는 것을 필요로하지 않습니다. 라이브러리에서만 CI 인스턴스에 대한 참조를 만들어야합니다. 아마도이 함수는 이것을하는 맞춤식 것이지만,'$ ci = get_instance(); $ ci-> load->가 가장 일반적인 방법이다. –

관련 문제