2011-10-18 170 views
0

即時通訊有一個頁面,將插入用戶名,ID和用戶必須能夠上傳10個圖像。使用codeigniter上傳多個圖像

即時通訊的主要問題是當涉及到使用codeigniter上傳多個圖像。

  1. 可以有人建議我我如何可以通過每個個體 圖像陣列的每個圖像路徑,這樣我就可以把它傳遞給數據庫。

  2. ,並且如果用戶選擇要上載小於10倍的圖像,如2或5 然後我怎樣可以忽略,說一個文件尚未已上載到 選擇並JST通只有圖像中的誤差。

    <form method="post" action="uploader/go" enctype="multipart/form-data"> 
    <input name="username" type="text" /><br /> 
    <input name="nid" type="text" /><br /> 
    <input type="file" name="image1" /><br /> 
    <input type="file" name="image2" /><br /> 
    <input type="file" name="image3" /><br /> 
    <input type="file" name="image4" /><br /> 
    <input type="file" name="image5" /><br /> 
    <input type="file" name="image6" /><br /> 
    <input type="file" name="image7" /><br /> 
    <input type="file" name="image8" /><br /> 
    <input type="file" name="image9" /><br /> 
    <input type="file" name="image10" /><br /> 
    <input type="submit" name="go" value="Upload!!!" /> 
    </form> 
    

樣品控制器

$image_data=array('image_info' => $this->upload->data('image')); 
$image_path=$image_data['image_info']['full_path']; 

$data =array(
      'id'=>uniqid('id_'), 
        'nID'=>$this->input->post('nid'), 
      'username'=>$username, 
      'image1'=>$image_path 
} 

任何幫助將不勝感激。

回答

4

變化的輸入名稱:

<input type="file" name="image[1]" /><br /> 
<input type="file" name="image[2]" /><br /> 
<input type="file" name="image[3]" /><br /> 

代替和$this->upload->data('image')將是一個數組。

然後你就可以這樣做:

foreach($this->upload->data('image') as $image) { 
    passItToTheDatabase(); // your custom function 

} 
+0

涼...感謝,但如果選擇了什麼樣的圖像處理不當?我如何跳過那個錯誤? – LiveEn

+0

@LiveEn你有錯誤嗎? – Teneff

+3

你甚至可以爲evey文件字段設置'
'這樣IDs就會自動生成php – user973254