2011-05-05 58 views
2

我想用PHP和codeigniter上傳文件。我的問題是,我得到一個錯誤返回幫助用codeiginter上傳文件

您沒有選擇一個文件上傳。

我使用下面的代碼,

$config['upload_path'] = "./media/uploads/cv"; 
      $config['allowed_types'] = 'pdf|doc|docx'; 
      $config['max_size'] = '1000'; 

      $this->upload->initialize($config); 
      $this->upload->do_upload('cvfile'); 
      if($this->upload->display_errors()) 
      { 
       $data['error'] = $this->upload->display_errors(); 
       die(print_r($data['error'])); 
       $this->template->build('/users/candidate', $data); 
       return; 
      } 
      else 
      { 
       die(print_r($this->upload->data())); 
      } 

在我的HTML我有一個多形式,並以這樣的形式我使用下面的代碼,

<input type="file" class="small" id="cvfile" value="" name="cvfile"> 

我爲什麼會得到上述錯誤?

回答

1

這就是說PHP函數is_uploaded_file表示名稱爲cvfile的上傳文件不存在。您應該檢查您的多部分/表單聲明並驗證它是否有效,並確保您的PHP設置將允許您將上載的文件寫入臨時文件夾。

0

查看:

<?php echo form_open_multipart('home/.....');?>//going to next page 
     <input type="file" name="cvfile" /> 
</form> 

控制器:

$config['upload_path'] = './path'; // put here your path 
$config['allowed_types'] = 'pdf|doc|docx'; 
$config['max_size']  = '4096';  

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

if (!$this->upload->do_upload("cvfile")) { 
    echo $this->upload->display_errors(); die(); 
    $this->data['error'] = array('error' => $this->upload->display_errors()); 
} else { 
    $upload_result = $this->upload->data(); 
    print_r($upload_result['file_name']);//or print any valid 
}