让你同时上传 1000 个文件

作者:未知 来源:未知 添加时间:2006年7月2日 字体:

预备知识:javascript, PHP(少量)/Perl(少量)! 

测试环境:Windows2000 + IIS5 + PHP (Win98 + PWS + PHP3 失败,估计是配置出了问题) 

目录结构: 

/wwwroot/cgi-bin/fileup.php (文件接收) 

/wwwroot/www/test/phpfileup.htm (文件提交) 

/wwwroot/www/test/tmp/ (默认保存目录) 



前言:文件上传,简单又麻烦。下面是上传文件的提交页面,利用该页面你不仅可以生成 1000 个上传文件框(实际是任意多个 0~n ),而且可分别指出它们的保存路径。 

提交页面的文件输入框为命名为: file0,file1,...file100,...fileN 

提交页面的文件路径框为命名为: path0,path1,...path100,...pathN 

由于页面的生成非常简单,所以就不在此多解释了,用 javascript 定义了两个函数,check() 用于提交页面,create()用于生成文件上传框。如果你有什么更好的建议或有什么疑问请 Email: gearsoft@netease.com 



phpfileup.htm 

-------------------------------------------------------- 

<html> 

<head> 

<title></title> 

<style> 

.lbtn {font-family:verdana;font-size:10.5pt;} 

.ist {font-family:verdana;font-size:14.8px;size:400} 

</style> 



<script LANGUAGE="javascript"> 

function check(){ 

document.frm1.submit(); 

document.body.innerHTML="Uploading Please wait!"; 





var i=0; 

function create(){ 

var sfrm = document.frm1.innerHTML; 

var icnt = cnt.&#118alue; 

for(j=0;j<icnt;j++) 



sfrm = sfrm + "请选择文件 "+i+" <input type=file name='file"+i+"' class=ist>"; 

sfrm = sfrm + " 路径:<input type=text name='path"+i+"' &#118alue='../www/test/tmp/' class=ist>"; 

sfrm = sfrm + "<br>"; 

i++; 



document.frm1.innerHTML = sfrm; 

document.frm1.cnt.&#118alue=i; 





</script> 



</head> 

<body class=lbtn onload="document.frm1.cnt.&#118alue=cnt.&#118alue;"> 

请输入要上传文件的数量: <input type=text name=cnt &#118alue="10" class=ist onchange="document.frm1.cnt.&#118alue=this.&#118alue;"> 

<input type=button name=bt1 &#118alue="生成上传文件框" &#111nclick="create();" class=lbtn> 

<input type=button name=bt1 &#118alue="上传" &#111nclick="check();" class=lbtn> 

<input type=button name=bt1 &#118alue="清除" &#111nclick="document.location.reload();" class=lbtn> 



<form name=frm1 method="post" Enctype="multipart/form-data" action="../../cgi-bin/fileup.php"> 

<input type=hidden name=cnt &#118alue="20" class=ist> 

</form> 



<input type=button name=bt1 &#118alue="上传" &#111nclick="check();" class=lbtn> 

<input type=button name=bt1 &#118alue="清除" &#111nclick="document.location.reload();" class=lbtn> 

</body> 

</html>

ppdesk