3

在codeigniter 2我必須做一個多文件上傳。Codeigniter多文件上傳

在我看來輸入元素看起來像這樣

<input type="file" name="file[]" id="file_1" /> 
<input type="file" name="file[]" id="file_2" /> 
<input type="file" name="file[]" id="file_3" /> 
<input type="file" name="file[]" id="file_4" /> 
<input type="file" name="file[]" id="file_5" /> 
<input type="file" name="file[]" id="file_6" /> 

普萊舍幫助我如何寫控制器上傳這些文件.. GOOGLE了很多..謝謝提前

+1

Google說了些什麼?你有什麼嘗試? Wat確實是$ _FILES嗎? – giorgio 2012-02-14 12:21:33

+1

試過了什麼?發佈您的代碼到目前爲止。另外,你可以在這裏找到許多類似的問題。使用本地上傳類進行多次上傳幾乎只是使用循環的問題。例如,http://stackoverflow.com/questions/1908247/codeigniter-multiple-file-upload – 2012-02-14 12:24:08

+0

在我的控制器中,我只寫了 $ images = $ _ FILES ['file']; $ res = $ this-> admins-> addPlace($ insertdata,$ images); 它只是將它發送到我的管理員模型。 有我stucked與環..請幫助 – ramesh 2012-02-14 12:24:20

回答

6

您可以上傳任意數量的文件的

$config['upload_path'] = 'upload/Main_category_product/'; 
$path=$config['upload_path']; 
$config['allowed_types'] = 'gif|jpg|jpeg|png'; 
$config['max_size'] = '1024'; 
$config['max_width'] = '1920'; 
$config['max_height'] = '1280'; 
$this->load->library('upload', $config); 

foreach ($_FILES as $key => $value) { 

    if (!empty($value['tmp_name']) && $value['size'] > 0) { 

     if (!$this->upload->do_upload($key)) { 

      $errors = $this->upload->display_errors(); 
      flashMsg($errors); 

     } else { 
      // Code After Files Upload Success GOES HERE 
     } 
    } 
} 

並嘗試使用HTML這樣的:

<input type="file" name="file1" id="file_1" /> 
<input type="file" name="file2" id="file_2" /> 
<input type="file" name="file3" id="file_3" /> 
+0

嗨感謝您的答覆,我得到這個錯誤...請幫助遇到 一個PHP錯誤 嚴重性:注意 消息:數組字符串轉換 文件名:libraries/Upload.php 行號:161 – ramesh 2012-02-14 13:14:04

+1

你有沒有試過確切的代碼? – srbhbarot 2012-02-14 13:18:10

+0

嗨srbhbarot ..請找到我的下面的答案..我得到的錯誤..請幫助 – ramesh 2012-02-14 13:22:23