2012-02-16 28 views
0

我想在CodeIgniter中使用多個文件上傳,但出現錯誤: You did not select a file to upload在Codeigniter中上傳多個文件時出錯

我的html代碼:

<input type="file" id="ModelImage" name="ModelImage[]" multiple="multiple" value=""/> 

我的PHP代碼:

for($i = 0; $i < count($_FILES['ModelImage']["name"]); $i++) 
{ 
    if (!empty($_FILES['ModelImage']['name'][$i])) 
    { 
    $config['upload_path'] = './uploads/starmodel/'; 
    $config['allowed_types'] = 'gif|jpg|png'; 
    $config['file_name']= "star_".$lastid."_".$i.strrchr(basename($_FILES["ModelImage"]["name"][$i]),"."); 
    $this->upload->initialize($config); 

    if ($this->upload->do_upload('ModelImage')) 
    { 
     $data = $this->upload->data(); 
     $udata = array('ModelImage' => $config['file_name']); 
     $this->db->where('ModelID', $lastid); 
     $this->db->update('starmodel', $udata); 
    } 
    else 
    { 
     echo $this->upload->display_errors(); 
    } 
    } 
} 

回答

0

名稱參數必須是userfile的

根據to the CI File Uploading Documentation

By default the upload routine expects the file to come from a form field called userfile, and the form must be a "multipart" type:

<form method="post" action="some_action" enctype="multipart/form-data" /> 
    <input type="file" name="userfile" size="20" /> 
    <input type="submit" value="upload" /> 
</form> 

這樣說,我不認爲CI的圖書館目前支持HTML5的多個文件上傳。自定義庫應該爲peak around CI's forums

+0

感謝您的重播。 @jordan Arsenault – 2012-02-16 08:50:08