《PHP應用:php 使用html5實現多文件上傳實例》要點:
本文介紹了PHP應用:php 使用html5實現多文件上傳實例,希望對您有用。如果有疑問,可以聯系我們。
PHP編程首先向大家介紹一下html5中file的multiple屬性
PHP編程定義和用法
PHP編程multiple 屬性規定輸入字段可選擇多個值.如果使用該屬性,則字段可接受多個值.
PHP編程實例:
PHP編程
<form action="demo_form.asp" method="get">
Select images: <input type="file" name="img" multiple="multiple" />
<input type="submit" />
</form>
PHP編程上面實例中的input file 可接受多個文件上傳字段.
PHP編程了解了html5中file的multiple屬性,下面我們開始講解使用html5實現多文件上傳.
PHP編程實例代碼:
PHP編程html:
PHP編程
<!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編程php代碼:
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編程感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/2962.html