php 使用html5實現(xiàn)多文件上傳實例
更新時間:2016年10月24日 08:22:24 投稿:lqh
在html沒有出來之前,要實現(xiàn)php多文件上傳比較麻煩,需要在form表單里面添加多個input file域。html5發(fā)布以后,我們可以使用input file的html5屬性multiple來實現(xiàn)多文件上傳,需要的朋友可以參考下
首先向大家介紹一下html5中file的multiple屬性
定義和用法
multiple 屬性規(guī)定輸入字段可選擇多個值。如果使用該屬性,則字段可接受多個值。
實例:
<form action="demo_form.asp" method="get"> Select images: <input type="file" name="img" multiple="multiple" /> <input type="submit" /> </form>
上面實例中的input file 可接受多個文件上傳字段。
了解了html5中file的multiple屬性,下面我們開始講解使用html5實現(xiàn)多文件上傳。
實例代碼:
html:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> <form action="my_parser.php" method="post" enctype="multipart/form-data"> <p><input name="upload[]" type="file" multiple="multiple" /></p> <input type="submit" value="Upload all files"> </form> </body> </html>
php代碼:
for($i=0; $i<count($_FILES['upload']['name']); $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['upload']['tmp_name'][$i];
//Make sure we have a filepath
if ($tmpFilePath != ""){
//Setup our new file path
$newFilePath = "./uploadFiles/" . $_FILES['upload']['name'][$i];
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $newFilePath)) {
//Handle other code here
}
}
}
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
您可能感興趣的文章:
- php 下 html5 XHR2 + FormData + File API 上傳文件操作實例分析
- PHP使用HTML5 FileApi實現(xiàn)Ajax上傳文件功能示例
- php+html5實現(xiàn)無刷新圖片上傳教程
- 使用PHP和HTML5 FormData實現(xiàn)無刷新文件上傳教程
- php+html5+ajax實現(xiàn)上傳圖片的方法
- php+html5使用FormData對象提交表單及上傳圖片的方法
- PHP 文件上傳進度條的兩種實現(xiàn)方法的代碼
- php實現(xiàn)簡單的上傳進度條
- php上傳文件并顯示上傳進度的方法
- PHP+Ajax無刷新帶進度條圖片上傳示例
- PHP+Ajax實現(xiàn)上傳文件進度條動態(tài)顯示進度功能
- php 使用html5 XHR2實現(xiàn)上傳文件與進度顯示功能示例
相關文章
laravel 實現(xiàn)上傳圖片到本地和前臺訪問示例
今天小編就為大家分享一篇laravel 實現(xiàn)上傳圖片到本地和前臺訪問示例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10
Zend Framework入門教程之Zend_View組件用法示例
這篇文章主要介紹了Zend Framework中Zend_View組件用法,結合實例形式簡單分析了Zend_View組件視圖操作的相關技巧與注意事項,需要的朋友可以參考下2016-12-12
CodeIgniter開發(fā)實現(xiàn)支付寶接口調用的方法示例
這篇文章主要介紹了CodeIgniter開發(fā)實現(xiàn)支付寶接口調用的方法,結合實例形式分析了CodeIgniter開發(fā)支付寶接口的操作步驟與相關實現(xiàn)技巧,需要的朋友可以參考下2016-11-11
Yii視圖CGridView實現(xiàn)操作按鈕定義地址示例
這篇文章主要介紹了Yii視圖CGridView實現(xiàn)操作按鈕定義地址的方法,涉及Yii視圖按鈕操作相關技巧,需要的朋友可以參考下2016-07-07

