多文件上傳的例子
//upload_html.php---------------------------------------------------------------------------------------------
<HTML>
<HEAD>
<TITLE>上傳文件</TITLE>
</HEAD>
<script>
function beforesubmit(forma)
{
var indexnamea=forma.indexname.value;
var upfilea=forma.upfile.value;
var k=/ /g;
var indexnamea=indexnamea.replace(k,"");
var upfilea=upfilea.replace(k,"");
if(indexnamea==""
upfilea=="")
{
alert("目錄名稱或上傳的目錄不能為空!");
return false;
}
return true;
}
</script>
<BODY BGCOLOR=WHITE>
<BR>
<form name=form1 action="upload.php" method=post enctype=\"multipart/form-data\" >\n";
<table cellspacing="1" cellpadding="5" border="0" width="580" bgcolor="#C2E2F5">
<tr bgcolor="#E3F2FB" align="center">
<td width="280" align="center" height="30">上傳的文件</td>
</tr>
<?
for($i=1;$i<8;$i++)
{
$upfile="upfile".strval($i);
echo " <tr>\n";
echo " <td bgcolor=#F5FBFE width=264><input type=file name=$upfile lengh=25></td>\n";
echo " </tr>\n";
}
?>
<tr bgcolor="#E3F2FB">
<td colspan="2" height="1">
</td>
<td colspan="2" height="1">
<div align="center">
<input type=submit name="submit" value=上傳>
</div>
</td>
</table>
</form>
</body></html>
//-----------------------------------------------------------------------------------------------------------------------
//upload.php-------------------------------------------------------------------------------------------------------------
//upload_path:文件要上傳到的目錄路徑
<?php
for($i=1;$i<8;$i++)
{
$upfile="upfile".strval($i);
if(chop($$indexname)!="" and chop($$upfile)!="")
{
$upfilename=($upfile."_name");
$filename=upload_path.$$upfilename;
$copyfile = copy($$upfile,$filename);
if (!$copyfile)
die("文件上傳失敗!");
$ls_file.=$$upfilename."\n";
$flag=1 ;
}
}
if($flag){
$ls_msg="文件\n".$ls_file."上傳成功!";
}
else{
$ls_msg="無文件上傳,請重新選擇!";
}
echo "<HTML>\n" ;
echo "<HEAD>\n" ;
echo "</HEAD>\n" ;
echo "<BODY >\n" ;
echo $ls_msg."\n";
echo "</BODY>\n" ;
echo "</HTML>\n" ;
?>