多文件上传的例子
程序员文章站
2022-10-05 21:40:29
多文件上传的例子
//upload_html.php-----------------...
多文件上传的例子 //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" ;
?>