php多文件上傳實(shí)現(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>上傳首頁(yè)中input的name屬性是這么設(shè)置的。
<2>用while循環(huán)上傳多文件。
相關(guān)文章
Laravel5.1 框架表單驗(yàn)證操作實(shí)例詳解
這篇文章主要介紹了Laravel5.1 框架表單驗(yàn)證操作,結(jié)合實(shí)例形式詳細(xì)分析了laravel5.1框架表單驗(yàn)證的具體實(shí)現(xiàn)步驟、實(shí)現(xiàn)方法及相關(guān)操作技巧,需要的朋友可以參考下2020-01-01
codeigniter框架The URI you submitted has disallowed characters
這篇文章主要介紹了codeigniter框架The URI you submitted has disallowed characters錯(cuò)誤解決方法,需要的朋友可以參考下2014-05-05
基于MySQL到MongoDB簡(jiǎn)易對(duì)照表的詳解
本篇文章是對(duì)從MySQL到MongoDB的簡(jiǎn)易對(duì)照表進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
通過(guò)dbi使用perl連接mysql數(shù)據(jù)庫(kù)的方法
這篇文章主要介紹了通過(guò)dbi使用perl連接mysql數(shù)據(jù)庫(kù)的方法,需要的朋友可以參考下2014-04-04
YII Framework學(xué)習(xí)之request與response用法(基于CHttpRequest響應(yīng))
這篇文章主要介紹了YII Framework學(xué)習(xí)之request與response用法,詳細(xì)介紹了CHttpRequest響應(yīng)request與response的使用技巧,需要的朋友可以參考下2016-03-03
PHP的foreach中使用引用時(shí)需要注意的一個(gè)問(wèn)題和解決方法
這篇文章主要介紹了PHP的foreach中使用引用時(shí)需要注意的一個(gè)問(wèn)題和解決方法,即數(shù)組最后一個(gè)元素的值會(huì)發(fā)生改變的情況,需要的朋友可以參考下2014-05-05
php實(shí)現(xiàn)生成帶二維碼圖片并強(qiáng)制下載功能
這篇文章主要介紹了php生成帶二維碼圖片并強(qiáng)制下載實(shí)現(xiàn)代碼,需要的朋友可以參考下2018-02-02

