<%@ language="javascript" %>
<html>
<head>
<title>上传图片文件</title>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
</head>
<body>
<%
//保存路径
var spath = "images/";
var self = Request.ServerVariables("SCRIPT_NAME");
if ((Request.ServerVariables("REQUEST_METHOD") + "").toLowerCase()=="post")
{
var fmLen = Request.TotalBytes;
var fmCont = Request.BinaryRead(fmLen);
var ext = getExt(fmCont);
var msg = "Not Allow Extension Of " + ext + " , Upload Fail !";
if (/\.(rar|bmp|jpg|gif)/i.test(ext))
{
var stm = Server.CreateObject("ADODB.Stream");
stm.Type = 1;
stm.Mode = 3;
stm.Open;
stm.Write(fmCont);
var s = stm.Position = getStart(fmCont);
var bstr = stm.Read(fmLen - s - 47);
var fileName = new Date().valueOf() + ext;
stm.Close();
stm.Open();
stm.Write(bstr);
stm.SaveToFile(Server.MapPath(spath + fileName));
stm.Close();
stm = null;
msg = "Upload File Succeed !";
}
Response.Write("\
<script type=\"text/javascript\">\
window.alert(\""+msg+"\");\
window.opener.sform.content.value += \"\\r\\n<img src=\\\"/Myart/images/" + fileName + "\\\">\";\
window.close();\
location.replace(\"" + self + "\");\
</script>");
}
function getExt(bstr)
{
var stm = Server.CreateObject("ADODB.Stream");
stm.Type = 2;
stm.Mode = 3;
stm.Open();
stm.WriteText(bstr);
stm.Position = 0;
stm.CharSet = "GB2312";
var fmText = stm.ReadText();
stm.Close();
stm = null;
return /filename=\".+(\..+)\"/.exec(fmText)[1];
}
%>
<script language="vbscript" runAt="server">
function getStart(bstr) : getStart = InStrB(1, bstr, ChrB(13) & ChrB(10) & ChrB(13) & ChrB(10)) + 3 : end function
</script>
<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>
posted on 2006-11-22 23:32
汪杰 阅读(7577)
评论(10) 编辑 收藏 引用 所属分类:
asp(javascrpt)