2012-03-23 43 views
0

我試圖從一個輸入一次上傳多個文件笨 - 上傳多個文件與一個輸入

<input type="file" name="form-image[]" id="form-image" multiple="true" />

而本身沒有CodeIgniter工作正常。在我嘗試使用CodeIgniterrs文件助手做同樣的事情時,我得到一個錯誤(is_uploaded_file() expects parameter 1 to be string, array given),這表明我做錯了什麼,或者CodeIgniter只是不支持多個文件?

我的錯誤代碼至今:

//Iterate through each file uploaded 
for ($i = 0; isset($_FILES['form-image']['name'][$i]); $i++) { 

    //Fix the settings 
    $config['upload_path'] = "./static/vimmel/"; 
    $config['file_name'] = time() . rand(1,988); 
    $config['allowed_types'] = 'gif|jpg|png'; 
    $config['max_size'] = '1024'; 
    $config['max_width'] = '1024'; 
    $config['max_height'] = '768'; 
    $this->load->library('upload', $config); 

    //Do the upload 
    $this->upload->do_upload("form-image") 
} 

請注意,我做編輯了所有的錯誤處理和這樣的。另請注意,我不使用is_uploaded_file()函數。

感謝所有的幫助和建議。謝謝。

+0

林不知道如果CI支持多文件上傳,我會堅持你原來的做法是否行得通,真正的線索是在名爲「幫手」。如果它對你沒有幫助,只是不要使用它。 – Philip 2012-03-23 20:22:39

+0

在這裏回答了它:http://stackoverflow.com/questions/9276756/codeigniter-multiple-file-upload/36943949#36943949 – 2016-04-29 17:09:42

回答

0

我使用的上傳庫的擴展,包括do_multiple_upload()函數接受文件的數組

https://github.com/nicdev/CodeIgniter-Multiple-File-Upload

它缺少了一些錯誤管理(例如,如果一個你文件沒有允許的擴展名,整個上傳失敗),但您可以更改循環中的繼續返回。

希望它可以幫助別人......