<script>
function addFileControl()
{
var str = '<input type="file" runat="server" style="width:80%" /><br>'
document.getElementById('FileCollection').insertAdjacentHTML("beforeEnd",str)
}
</script>
<FORM id=form1 encType=multipart/form-data runat="server">
<p id="FileCollection"><input type="file" runat="server" style="width:80%"/> <a href="javascript:;" onclick="addFileControl()">+</a> </p>
</FORM>
///////////////////////////////////////////////////////////////////////////////
System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
int fileCount;
int filecount = files.Count;
string rnd1;
string mPath1 = Server.MapPath("../../pimages/");
string img1;
for (fileCount = 1; fileCount < files.Count; fileCount++)
{
//定义访问客户端上传文件的对象
System.Web.HttpPostedFile postedFile = files[fileCount];
string fileName, fileExtension;
//取得上传得文件名
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != String.Empty)
{
rnd1 = "";
rnd1 = sqldata.rndNum() + fileCount.ToString(); //随机文件名
//取得文件的扩展名
fileExtension = System.IO.Path.GetExtension(fileName);
postedFile.SaveAs(mPath1 + rnd1 + fileExtension);
img1 = rnd1 + fileExtension;
}
}
////////////////////////////////////////////////////////////////////////////////