php多文件上傳實現(xiàn)代碼
index_uploads.php
<html>
<head>
<meta charset="utf-8">
<title>index_uploads</title>
</head>
<body>
<form action="uploads.php" method="post" enctype="multipart/form-data">
<input type="file" name="file[]">
<br>
<input type="file" name="file[]">
<br>
<input type="submit" value="uploads">
</form>
</body>
</html>
uploads.php
<?php
header("content-type:text/html;charset=utf-8");
echo "<pre>";
print_r($_FILES);
echo "</pre>";
$count = count($_FILES['file']['name']);
for ($i = 0; $i < $count; $i++) {
$tmpfile = $_FILES['file']['tmp_name'][$i];
$filefix = array_pop(explode(".", $_FILES['file']['name'][$i]));
$dstfile = "uploads/files/".time()."_".mt_rand().".".$filefix;
if (move_uploaded_file($tmpfile, $dstfile)) {
echo "<script>alert('succeed!');window.location.href='index_uploads.php';</script>";
} else {
echo "<script>alert('fail!');window.location.href='index_uploads.php';</script>";
}
}
核心:<1>上傳首頁中input的name屬性是這么設置的。
<2>用while循環(huán)上傳多文件。
相關文章
thinkPHP5框架整合plupload實現(xiàn)圖片批量上傳功能的方法
這篇文章主要介紹了thinkPHP5框架整合plupload實現(xiàn)圖片批量上傳功能的方法,結(jié)合實例形式分析了thinkPHP結(jié)合pluploadQueue實現(xiàn)上傳功能的相關操作技巧,需要的朋友可以參考下2017-11-11PHP實現(xiàn)抓取Google IP并自動修改hosts文件
這篇文章主要介紹了PHP實現(xiàn)抓取Google IP并自動修改hosts文件,本文方法可以實現(xiàn)免翻墻上google,小編親測可用,需要的朋友可以參考下2015-02-02關于PHP的相似度計算函數(shù):levenshtein的使用介紹
本篇文章小編將為大家介紹,關于PHP的相似度計算函數(shù) levenshtein的使用介紹,有需要的朋友可以參考一下2013-04-04php使用get和post傳遞數(shù)據(jù)出現(xiàn)414?Request-URI?Too?Large的原因分析及解決方案
Request-URI Too Large(請求URI過長)是一個HTTP錯誤狀態(tài)碼,表示所發(fā)送的HTTP請求中的URI(統(tǒng)一資源標識符)長度超過了服務器能夠處理的限制,這篇文章主要介紹了php使用get和post傳遞數(shù)據(jù)出現(xiàn)414?Request-URI Too?Large的解決方案,需要的朋友可以參考下2023-08-08