2016-03-25 38 views
2

我想upload圖片在codeigniter。但我得到這個錯誤如何在codeigniter框架中上傳文件

失敗=你沒有選擇一個文件上傳。

我的代碼:

function uploadImageAvatar(){ 


     $config = array(
      'upload_path' => "/public_html/assets/Vitrin/Avatars/", 
      'allowed_types' => "gif|jpg|png|jpeg|pdf", 
      'overwrite' => FALSE, 
      'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb) 
      'max_height' => "768", 
      'max_width' => "1024" 
     ); 

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

     if($this->upload->do_upload($_FILES['image_file']['tmp_name'])) 
     { 
      echo "successful"; 

     } 
     else 
     { 

      echo "unsuccessful=".$this->upload->display_errors(); 
     } 
} 

我的HTML:

<form action="{{base_url().'cp/Users/uploadImageAvatar'}}" method="post" enctype="multipart/form-data" id="upload_form"> 

      <input name="image_file" type="file" required="true" /> 

      <input type="submit" value="upload" id="submit-btn" /> 
</form> 

其中我錯了?

+0

只是改變臨時名稱'$這個 - > upload-> do_upload($ _ FILES [ 'IMAGE_FILE'] [ '名'])' – Saty

+0

但我得到相同的錯誤。 –

+0

嘗試使用$ this-> upload-> do_upload('image_file')這裏是示例http://www.experts-exchange.com/questions/26381226/Codeigniter-File-Uploading-Error.html –

回答

3

改變這一行

if($this->upload->do_upload($_FILES['image_file']['tmp_name'])) 

if($this->upload->do_upload('image_file'))