当前位置:编程学习 > asp >>

防止用户上传产生无效文件源码

经过近日来的调试,狂人于4月12日写的一篇日志“用户上传产生无效文件的解决思路”代码部分已经完成。欢迎批评指正,以便改进。
[FileName]:upload.asp
[Code]:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#i nclude virtual="upload.inc"-->
<%
 If Request.ServerVariables("REQUEST_METHOD")="POST" then
'表单提交执行
    CONST upFileSize=100 '文件大小限制,单位:KB
    CONST upFileType=".gif.jpg.jpeg" '文件类型限制,可根据需要修改
    CONST targetPath="/publish/images/" '以网站为根目录的文件存放路径,以"/"结束
    
    dim upload,thisFile,formName,iCount
    set upload=new upload_5xSoft ''建立上传对象
    Flag=True '初始化文件上传标识
    for each formName in upload.ifile '列出上传文件的所有参数
     set thisFile=upload.ifile(formName)  '生成一个文件对象
     If thisfile.filesize=0 then
    Flag=False
    Msg="请选择你要上传的文件。"
    CALL showErr(Msg)
     end if
     if thisfile.filesize>upFileSize*1024 then
    Flag=False
    Msg="文件大小超过了限制。"
    CALL showErr(Msg)
     end if
     if Instr(upFileType,GetExtendName(thisfile.FileName))=0 then
    Flag=False
    Msg="文件格式不符合要求。"
    CALL showErr(Msg)
     end if
     
     If Flag then
    '创建临时上传文件夹
    tempPath="/publish/images/"&Session.SessionID&"/"
补充:asp教程,高级应用 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,