單個input框上傳多個檔案操作

來源:互聯網
上載者:User

標籤:

HTML頁面:

1 <div class="form-group thumb">2                                         <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="info">產品圖片上傳:</label>3 4                                         <div class="col-xs-12 col-sm-9" style="width:25%;">5 6                                             <div class="clearfix"><input type="file"  multiple="true" name="images[]" id="id-input-file-2" /></div>7 8                                         </div>9                                     </div>
multiple="true" name="images[]"
這兩個是比較重要的,也就是否則:1、無法多選檔案。2、上傳的檔案$_FILES只有一個檔案。
上傳後列印出檔案類型:


就這個樣子的格式,我們肯定是不能用Thinkphp的upload和uploadone方法去上傳檔案的。
 1 array 2 ( 3   1=>array( 4                ([name]=> 5                 [type]=>               6                ([name]=> 7                 [type]=>              8                ([name]=> 9                 [type]=> 10                )          11  2=>array(12                ([name]=>13                 [type]=>              14                ([name]=>15                 [type]=>             16                ([name]=>17                 [type]=> 18                )      19 )20     

 

 


所以自己寫一個方法去處理成
1                     if(array_sum($_FILES[‘images‘][‘size‘])>0){2                         $tmp=array();3                         foreach ($_FILES[‘images‘] as $k => $v) {4                             foreach ($v as $kk => $vv) {5                                 $tmp[$kk][$k]=$vv;6                             }7                         }8                         $images=fab_upload($tmp);9                         $input[‘images‘]=serialize($images);

 

處理了以後就相當於多個input框一個inpuit框對應一個上傳檔案的樣子得到的$_FILES資料,然後將含有一上傳資訊(上傳檔案在伺服器的儲存路徑)進行序列化,存入text儲存類型的儲存欄位之中嗎,顯示圖片的時候,當然是unserialize還原序列化咯!


 

單個input框上傳多個檔案操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.