ASP不支持multipart/form-data编码方式,但是,Microsoft提供了免费的Posting Acceptor(http://www.microsoft.com/iis/support/iishelp/iis/htm/core/pareadme.htm),它是一个ISAPI应用程序,上载结束后,产生一个到ASP页的重新投递。(见 Scott Stanfield的文章 issue of MIND(98年七月))。
Software Artisans的SA-FileUp
SA-FileUp(http://www.softartisans.com/softartisans/saf.html)是最早的商业活动服务器组件(Active Server Components)之一。第一版是97年5月开始使用的,现在全世界包括Microsoft.com在内的上千个网站都在使用它。早期的Beta版本用ISAPI过滤器和活动服务器组件的联合体与ASP结合起来。接着,Microsoft推出了ASP 1.0b(ASP.DLL 1.15.14.0),提供了一种新方法:Request.BinaryRead(二进制读请求)。二进制读方法使浏览器中的原始未加工数据可以被活动服务器组件使用。这样一来,SA-FileUp就不再需要ISAPI过滤器,而作为一个ASP组件存在了。
Enter first filename: < input type="file" name="f1" > Enter second filename: < input type="file" name="f2" > 格式处理是一样的:
< %@ LANGUAGE="VBSCRIPT" % > < HTML >< HEAD > < TITLE >Multiple File Upload Results< /TITLE > < /HEAD > < BODY > Thank you for uploading your files. < % Set upl = Server.CreateObject("SoftArtisans.FileUp") % > < % upl.Form("f1").SaveAs "C: empupload1.out" % > Total Bytes Written for file 1: < %=upl.Form("f1").TotalBytes% > < % upl.Form("f2").SaveAs "C: empupload2.out" % > Total Bytes Written for file 2: < %=upl.Form("f2").TotalBytes% > < /BODY > < /HTML > 限制上载规模
要限制上载规模,只需要设置一个属性:
< %@ LANGUAGE="VBSCRIPT" % > < HTML >< HEAD > < TITLE >Upload File Results< /TITLE > < /HEAD > < BODY > Thank you for uploading your file. < % Set upl = Server.CreateObject("SoftArtisans.FileUp") % > < % upl.MaxBytes = 1000 '--- limit the upload size to 1000 bytes % > The maximum size that you are permitted to upload is < %=upl.MaxBytes% > bytes per file. < % upl.SaveAs "C: empupload.out" % > Total Bytes Written: < %=upl.TotalBytes% > Server Filename: < %=upl.ServerName% > Total Bytes Transmitted by you: < %=Request.TotalBytes% > < /BODY > < /HTML > 第1000个字节后的内容都将被删除,WEB服务器的磁盘就不会不必要地被占满。