欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ASP实例:一个简单的ASP无组件上传类

程序员文章站 2022-05-02 14:24:26
简单的asp无上传类,发出来让大家看看。可以做做实验! <%@ language="javascript"%><%...

简单的asp无上传类,发出来让大家看看。可以做做实验!

<%@ language="javascript"%>
<%
var self = request.servervariables("script_name");
if (request.servervariables("request_method")=="post")
{
        var oo = new uploadfile();
        oo.path = "myfile";                        //存放路径,为空表示当前路径,默认为uploadfile
        oo.named = "file";                        //命名方式,date表示用日期来命名,file表示用文件名本身,默认为file
        oo.ext = "all";                                //允许上传的扩展名,all表示都允许,默认为all
        oo.over = true;                                //当存在相同文件名时是否覆盖,默认为false
        oo.size = 1*1024*1024;                //最大字节数限制,默认为1g
        oo.upload();
        response.write(<script type="text/javascript">location.replace("+self+")</script>);
}

//asp无组件上传类
function uploadfile()
{
    var blen  = request.totalbytes;
    var btext = request.binaryread(blen);
    var oo = server.createobject("adodb.stream");
    oo.mode = 3;
        this.path = "uploadfile";
        this.named = "file";
        this.ext = "all";
        this.over = false;
        this.size = 1*1024*1024*1024;        //1gb

        //文件上传       
        this.upload = function ()
        {
                var o = this.getinfo();
                if (o.size>this.size)
                {
                        alert("文件过大,不能上传!");
                        return;               
                }
                var f = this.getfilename();
                var ext = f.replace(/^.+./,"");
                if (this.ext!="all"&&!new regexp(this.ext.replace(/,/g,"|"),"ig").test(ext))
                {
                        alert("目前暂不支持扩展名为 "+ext+" 的文件上传!");
                        return;
                }
                if (this.named=="date")
                {
                        f = new date().tolocalestring().replace(/d/g,"") + "." + ext;
                }

                oo.open();
                oo.type = 1;
                oo.write(o.bin);
                this.path = this.path.replace(/[^/\]$/,"$&/");
                var fso = server.createobject("scripting.filesystemobject");
                if(this.path!=""&&!fso.folderexists(server.mappath(this.path)))
                {
                        fso.createfolder(server.mappath(this.path));
                }
                try
                {
                        oo.savetofile(server.mappath(this.path+f),this.over?2:1);
                        alert("上传成功!");
                }
                catch(e)
                {
                        alert("对不起,此文件已存在!");
                }
                oo.close();
                delete(oo);

        }

        //获取二进制和文件字节数
        this.getinfo = function ()
        {
                oo.open();
        

点击复制链接 与好友分享!
相关tag标签
上一篇:简述从五个方面优化asp程序
下一篇:asp类型个人网站与动网整合非官方方法
相关文章
热门专题推荐 android sdk
图文推荐