JavaScript版无组件上传类
作者:编程浪子 来源:51js 发布时间:2007-10-06 23:16:00
标签:上传,无组件,javascript
asp无组件上传VBS编写的大家见的多了,这个是纯javascript实现的上传,原来unicode可以解决读取位置的问题,这次真的是纯JS了,VBS终于可以退休了,发出来让大家看看。
<%@ language="javascript"%>
<%
var self = Request.serverVariables("SCRIPT_NAME");
if (Request.serverVariables("REQUEST_METHOD")=="POST")
{
var oo = new uploadFile();
oo.path = ""; //存放路径,为空表示当前路径,默认为uploadFile
oo.named = "date"; //命名方式,date表示用日期来命名,file表示用文件名本身,默认为file
oo.ext = "jpg,gif,rar"; //允许上传的扩展名,all表示都允许,默认为all
oo.over = true; //当存在相同文件名时是否覆盖,默认为false
oo.size = 2*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();
oo.type=1;
oo.write(bText);
oo.position = 0;
oo.type=2;
oo.charset="unicode";
var gbCode=escape(oo.readText()).replace(/%u(..)(..)/g,"%$2%$1");
var sPos=gbCode.indexOf("%0D%0A%0D%0A")+12;
var sLength=bLen-(gbCode.substring(0,gbCode.indexOf("%0D%0A")).length/3)-sPos/3-6;
oo.close();
oo.open();
oo.type = 1;
oo.write(bText);
oo.position=sPos/3;
var bFile=oo.read(sLength);
oo.close();
return { bin:bFile, size:sLength };
}
//获取文件名
this.getFileName = function ()
{
oo.open();
oo.type = 2;
oo.writeText(bText);
oo.position = 0;
oo.charset = "gb2312";
var fileName = oo.readText().match(/filename=\"(.+?)\"/i)[1].split("\\").slice(-1)[0];
oo.close();
return fileName;
}
function alert(msg)
{
Response.write(’<script type="text/javascript">alert("’+msg+’");</script>’);
}
}
%>
<html>
<head>
<title>ASP无组件上传类(JS版)</title>
<meta http-equiv="content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form action="<%=self%>" method="post" enctype="multipart/form-data" onSubmit="return (this.upFile.value!=’’);">
<input type="file" name="upFile"/>
<input type="submit" value="上传文件"/>
</form>
</body>
</html>
0
投稿
猜你喜欢
- 本文实例为大家分享了python实现大转盘抽奖的具体代码,供大家参考,具体内容如下选择转盘中的某一个方框,来进行抽奖import tkint
- 一、首先从SQLServer中Error讲起,SQL中错误处理有些怪辟 错误级别同是16但结果都不同。select *
- 本文实例讲述了php基于协程实现异步的方法。分享给大家供大家参考,具体如下:github上php的协程大部分是根据这篇文章实现的:http:
- 一、简介time模块提供各种操作时间的函数说明:一般有两种表示时间的方式:第一种是时间戳的方式(相对于1970.1.1 00:00:00以秒
- 第一步:获取mysql YUM源进入mysql官网获取RPM包下载地址https://dev.mysql.com/downloads/rep
- 从两个优秀的世界各取所需,更高效的复用代码。想想就醉了,.NET和python融合了。“懒惰”的程序员们,还等什么?Jesse Smith为
- 关于多维数组如何复合排序如数组:>>> import numpy as np>>> data = np.
- 建立一个数据库表维护规范在一个定期基础而非等到问题出现才实施数据库表的检查是一个好主意。应该考虑到建立一个预防性维护的时间表,以协助自动问题
- django框架默认将session保存到数据库中,在高并发访问无疑会影响服务器性能,因此最好将session保存到redis中避免直接从数
- 工具:Pycharm,Django1.11.9.1.下载django_admin_bootstrappedpip install djang
- 求3721,163,1,4832,1980,2008,68686688,9999,17173,5173,8848中最大的数明白后,试着求一下
- MD5(Message-Digest Algorithm 5) 模块用于计算信息密文(信息摘要),得出一个128位的密文。sha模块跟md5
- 实现对图像进行简单的高斯去噪和椒盐去噪。代码如下:import numpy as npfrom PIL import Imageimport
- 写入:1:把gif图像文件读入内存(一个变量strTemp)。2:写入数据库。Dim binTmp() As ByteDim conn As
- 主要有五个方面:一..HTML页面转UTF-8编码问题二.PHP页面转UTF-8编码问题三.MYSQL数据库使用UTF-8编码的问题四.JS
- 一 、MySQL版本查询1)登录mysql首先Window+R然后在命令行里输入mysql -u此处填你的mysql账号(注意要加-u) -
- User模型 User模型是这个框架的核心部分。他的完整的路径是在django.contrib.auth.models.User。字段 内置
- 微信小程序开发中窗口底部tab栏切换页面很简单很方便.代码:1.app.json//app.json { "pages"
- 本文实例讲述了Python基于聚类算法实现密度聚类(DBSCAN)计算。分享给大家供大家参考,具体如下:算法思想基于密度的聚类算法从样本密度
- 导语之前有很多小伙伴说想学习一下多线程图片下载器,虽然好像已经过去很久了,不过还是上来安排一波吧。至于题目为什么说是构建一个小型数据集,因为