ASP实现上传功能二
时间:2009-01-12 来源:hkebao
刚才我们总结了如何可以通过无组件类进行上传操作,那现在我们来总结一下如何通过组件上传功能呢?
第一步:将我们的上传组件注册到系统中去
第二步:写代码实现功能
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp") '建立上传对象
ContentTpye = trim(oFileUp.Form("FileName").contentType) '取出来文件类型
《其中的FileName表示的是表单中的File类型的名称》
<input type="file" name="FileName">
'提取出来这个表单项中的文件流类型
if ContentTpye<>"image/x-png" and ContentTpye<>"image/gif" and ContentTpye<>"image/bmp" and ContentTpye<>"image/pjpeg" and ContentTpye<>"image/jpeg" then
response.Write "文件类型不正确[只能是.bmp,.jpg,jpeg,.gif,.png格式]"
oFileUp.Flush
response.End
end if
if oFileUp.Form("FileName").TotalBytes > MaxBytes then '这个文件的字节大小
response.Write "文件超过限制不能上传!"
oFileUp.Flush
response.End
end if
small=now()
small=hour(small)&minute(small)&second(small)&cstr(fix(rnd*10000))
small=small& Right(ShortFilename,4)
saveMapPath=server.MapPath("/UploadFiles/"&small&"")
oFileUp.Form("FileName").SaveAs saveMapPath '将文件保存到服务器上面去了!
提取上传表单中的内容是这样来处理的:
oFileUp.form("select")
可以得到上传表单中的名为
相对于无组件上传来说有组件要方便许多哦!
第一步:将我们的上传组件注册到系统中去
第二步:写代码实现功能
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp") '建立上传对象
ContentTpye = trim(oFileUp.Form("FileName").contentType) '取出来文件类型
《其中的FileName表示的是表单中的File类型的名称》
<input type="file" name="FileName">
'提取出来这个表单项中的文件流类型
if ContentTpye<>"image/x-png" and ContentTpye<>"image/gif" and ContentTpye<>"image/bmp" and ContentTpye<>"image/pjpeg" and ContentTpye<>"image/jpeg" then
response.Write "文件类型不正确[只能是.bmp,.jpg,jpeg,.gif,.png格式]"
oFileUp.Flush
response.End
end if
if oFileUp.Form("FileName").TotalBytes > MaxBytes then '这个文件的字节大小
response.Write "文件超过限制不能上传!"
oFileUp.Flush
response.End
end if
small=now()
small=hour(small)&minute(small)&second(small)&cstr(fix(rnd*10000))
small=small& Right(ShortFilename,4)
saveMapPath=server.MapPath("/UploadFiles/"&small&"")
oFileUp.Form("FileName").SaveAs saveMapPath '将文件保存到服务器上面去了!
提取上传表单中的内容是这样来处理的:
oFileUp.form("select")
可以得到上传表单中的名为
相对于无组件上传来说有组件要方便许多哦!
相关阅读 更多 +