跪求高手检查asp上传类源码错误所在?(不能上传!!!)
<%@LANGUAGE="VBSCRIPT"CODEPAGE="936"%><!--#includefile="upload_class.asp"--><!DOCTYPE...
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="upload_class.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>文件上传</title>
<style type="text/css">
body{margin:0px;}
body,td{font-size:12px; color:#000000;}
a{color:#0000FF; text-decoration:underline;}
a:hover{ color:#FF0000;}
</style>
<script language="javascript">
function oCopy(obj)
{
obj.select();
js=obj.createTextRange();
js.execCommand('Copy');
}
</script>
</head>
<body>
<%
Dim FilePath,upload,FileExe,FileExeTmp,fso
Const AllowExe = "jpg,gif,bmp,png,zip,rar,doc,xls,txt,swf"
Const AllowSize = 1024
FilePath = ""
If Trim(Request.QueryString("action")) = "save" Then
If Session("Ok3w_Upfiles_UserName")="" Then
Response.Write("你还没有登陆或是登陆已经超时。")
Response.End()
End If
Set upload = New upload_5xsoft
Set file=upload.file("file")
If file.FileSize>0 then
FileExeTmp = Split(file.FileName,".")
FileExe = Lcase(FileExeTmp(Ubound(FileExeTmp)))
If file.FileSize>AllowSize*1024 Then
Response.Write("文件大小不能超过" & AllowSize & "KB,请<a href=""upload_files.asp"">返回</a>。")
Response.End()
End If
If InStr("," & AllowExe & ",","," & FileExe & ",") <=0 Then
Response.Write("不允许上传该类型文件,请<a href=""upload_files.asp"">返回</a>。")
Response.End()
End If
FilePath = "upfiles/edit/" & Year(Date()) & Right("0"&Month(Date()),2) & "/"
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(Server.MapPath("../" & FilePath)) Then
fso.CreateFolder(Server.MapPath("../" & FilePath))
End If
Set fso = Nothing
FilePath = FilePath & Year(Date()) & Right("0" & Month(Date()),2) & Right("0" & Day(Date()),2) & Right("0" & Hour(Time()),2) & Right("0" & Minute(Time()),2) & Right("0" & Second(Time()),2) & "." & FileExe
file.SaveAs Server.mappath("../" & FilePath)
End If
Set file = Nothing
Set upload = Nothing
End If
%>
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="?action=save">
<%If FilePath="" Then%>
<input type="file" name="file" style="width:200px; border:1px solid #666666;" onKeyPress="return false;" />
<input type="button" name="Submit" value="上传" style="border:1px solid #666666;" Click="this.disabled=true;this.value='稍候';this.form.submit();" />
<%Else%>
<input name="FilePath" type="text" value="<%=FilePath%>" onClick="oCopy(this);" readonly="readonly" style="width:200px; border:1px solid #666666;" />
<a href="upload_files.asp">新上传</a>
<script language="javascript">oCopy(document.form1.FilePath);</script>
<%End If%>
</form>
</body>
</html> 展开
<!--#include file="upload_class.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>文件上传</title>
<style type="text/css">
body{margin:0px;}
body,td{font-size:12px; color:#000000;}
a{color:#0000FF; text-decoration:underline;}
a:hover{ color:#FF0000;}
</style>
<script language="javascript">
function oCopy(obj)
{
obj.select();
js=obj.createTextRange();
js.execCommand('Copy');
}
</script>
</head>
<body>
<%
Dim FilePath,upload,FileExe,FileExeTmp,fso
Const AllowExe = "jpg,gif,bmp,png,zip,rar,doc,xls,txt,swf"
Const AllowSize = 1024
FilePath = ""
If Trim(Request.QueryString("action")) = "save" Then
If Session("Ok3w_Upfiles_UserName")="" Then
Response.Write("你还没有登陆或是登陆已经超时。")
Response.End()
End If
Set upload = New upload_5xsoft
Set file=upload.file("file")
If file.FileSize>0 then
FileExeTmp = Split(file.FileName,".")
FileExe = Lcase(FileExeTmp(Ubound(FileExeTmp)))
If file.FileSize>AllowSize*1024 Then
Response.Write("文件大小不能超过" & AllowSize & "KB,请<a href=""upload_files.asp"">返回</a>。")
Response.End()
End If
If InStr("," & AllowExe & ",","," & FileExe & ",") <=0 Then
Response.Write("不允许上传该类型文件,请<a href=""upload_files.asp"">返回</a>。")
Response.End()
End If
FilePath = "upfiles/edit/" & Year(Date()) & Right("0"&Month(Date()),2) & "/"
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(Server.MapPath("../" & FilePath)) Then
fso.CreateFolder(Server.MapPath("../" & FilePath))
End If
Set fso = Nothing
FilePath = FilePath & Year(Date()) & Right("0" & Month(Date()),2) & Right("0" & Day(Date()),2) & Right("0" & Hour(Time()),2) & Right("0" & Minute(Time()),2) & Right("0" & Second(Time()),2) & "." & FileExe
file.SaveAs Server.mappath("../" & FilePath)
End If
Set file = Nothing
Set upload = Nothing
End If
%>
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="?action=save">
<%If FilePath="" Then%>
<input type="file" name="file" style="width:200px; border:1px solid #666666;" onKeyPress="return false;" />
<input type="button" name="Submit" value="上传" style="border:1px solid #666666;" Click="this.disabled=true;this.value='稍候';this.form.submit();" />
<%Else%>
<input name="FilePath" type="text" value="<%=FilePath%>" onClick="oCopy(this);" readonly="readonly" style="width:200px; border:1px solid #666666;" />
<a href="upload_files.asp">新上传</a>
<script language="javascript">oCopy(document.form1.FilePath);</script>
<%End If%>
</form>
</body>
</html> 展开
2个回答
云创
2023-07-25 广告
2023-07-25 广告
要找到一家更省钱的代码静态分析服务,可以考虑以下几个方面:1. 了解自身的需求和预算:首先需要了解自己的项目对代码静态分析服务的需求,以及可承受的预算范围。这将有助于缩小选择范围,找到适合自己的服务。2. 调查市场上的竞争情况:了解市场上提...
点击进入详情页
本回答由云创提供
展开全部
我给你提供一个在浏览上传文件时就可以判断文件大小。比你上传后再判断。方便多。
代码你自己整理吧。
<html>
<head>
<script language="javascript"> document.domain="";</script>
<style>
<!--
body
td
INPUT
textarea
#sponsorAdDiv
-->
</style>
<Script language="javascript">
function mysubmit(theform)
{
if(theform.sf_upfile.value=="")
{
alert("请点击浏览按钮,选择您要上传的图片文件!")
theform.sf_upfile.focus;
return (false);
}
else
{
str= theform.sf_upfile.value;
strs=str.toLowerCase();
lens=strs.length;
extname=strs.substring(lens-4,lens);
if(extname!=".jpg" && extname!=".gif"&& extname!=".bmp")
{
alert("文件格式不对,请选择jpg或gif或bmp文件!");
return (false);
}
}
initAd();
return (true);
}
</script>
<SCRIPT LANGUAGE="JavaScript">
adTime=8;
chanceAd=1;
var ns=(document.layers);
var ie=(document.all);
var w3=(document.getElementById && !ie);
adCount=0;
function initAd(){
if(!ns && !ie && !w3) return;
if(ie) adDiv=eval('document.all.sponsorAdDiv.style');
else if(ns) adDiv=eval('document.layers["sponsorAdDiv"]');
else if(w3) adDiv=eval('document.getElementById("sponsorAdDiv").style');
randAd=Math.ceil(Math.random()*chanceAd);
if (ie||w3)
adDiv.visibility="visible";
else
adDiv.visibility ="show";
if(randAd==1) showAd();
}
function showAd(){
if(adCount<adTime*10){adCount+=1;
if (ie){documentWidth =document.body.offsetWidth/2+document.body.scrollLeft-20;
documentHeight =document.body.offsetHeight/2+document.body.scrollTop-20;}
else if (ns){documentWidth=window.innerWidth/2+window.pageXOffset-20;
documentHeight=window.innerHeight/2+window.pageYOffset-20;}
else if (w3){documentWidth=self.innerWidth/2+window.pageXOffset-20;
documentHeight=self.innerHeight/2+window.pageYOffset-20;}
adDiv.left=documentWidth-100;adDiv.top =documentHeight-0;
setTimeout("showAd()",100);}
}
function closeAd(){
if (ie||w3)
adDiv.display="none";
else
adDiv.visibility ="hide";
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>
<body background="../images/bg2.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div id="sponsorAdDiv" style="visibility:hidden; left: 2px; top: 15px; width: 197px; height: 13px">
<table width="200" height="15" bgcolor="#0099cc" border=0 cellspacing=1>
<tr>
<td>
<table width="100%" height="100%" border=0 cellspacing=0>
<tr bgcolor="#d2e9fe">
<td> 正在上传图片,请稍候...... </td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<form method="POST" action="upload2.asp" enctype="multipart/form-data" name="uppic" onsubmit="return(mysubmit(this));" style="margin-top: 0; margin-bottom: 6" >
<script>
var img=null;
var maxsize = 100; //定义允许文件的大小,单位KB,请根据需要自行修改!
function s()
{
if(img)img.removeNode(true);
img=document.createElement("img");
img.style.position="absolute";
img.style.visibility="hidden";
img.width = 0;
img.height = 0;
img.attachEvent("onreadystatechange",orsc);
img.attachEvent("onerror",oe);
document.body.insertAdjacentElement("beforeend",img);
img.src=uppic.inp.value;
}
function oe()
{
alert("此文件非图片文件");
uppic.submit.disabled=true;
}
function orsc()
{
if(img.readyState!="complete")return false;
if(img.fileSize/1024>maxsize)
{
uppic.submit.disabled=true;
alert("抱歉!您选择的文件为 "+Math.round(img.fileSize/1024,2)+" KB,超过了程序"+maxsize+" KB 的限制!");
}
else
uppic.submit.disabled=false;
}
</script>
<p style="margin-top: 0; margin-bottom: 0">
<input id="inp" type=file name="sf_upfile" size="25" class="text" onchange="s()" >
<input type="submit" name="submit" value="上 传 图 片" class="text" >
<input type="hidden" name="boardid" value="">
</p>
</form>
</body></html>
代码你自己整理吧。
<html>
<head>
<script language="javascript"> document.domain="";</script>
<style>
<!--
body
td
INPUT
textarea
#sponsorAdDiv
-->
</style>
<Script language="javascript">
function mysubmit(theform)
{
if(theform.sf_upfile.value=="")
{
alert("请点击浏览按钮,选择您要上传的图片文件!")
theform.sf_upfile.focus;
return (false);
}
else
{
str= theform.sf_upfile.value;
strs=str.toLowerCase();
lens=strs.length;
extname=strs.substring(lens-4,lens);
if(extname!=".jpg" && extname!=".gif"&& extname!=".bmp")
{
alert("文件格式不对,请选择jpg或gif或bmp文件!");
return (false);
}
}
initAd();
return (true);
}
</script>
<SCRIPT LANGUAGE="JavaScript">
adTime=8;
chanceAd=1;
var ns=(document.layers);
var ie=(document.all);
var w3=(document.getElementById && !ie);
adCount=0;
function initAd(){
if(!ns && !ie && !w3) return;
if(ie) adDiv=eval('document.all.sponsorAdDiv.style');
else if(ns) adDiv=eval('document.layers["sponsorAdDiv"]');
else if(w3) adDiv=eval('document.getElementById("sponsorAdDiv").style');
randAd=Math.ceil(Math.random()*chanceAd);
if (ie||w3)
adDiv.visibility="visible";
else
adDiv.visibility ="show";
if(randAd==1) showAd();
}
function showAd(){
if(adCount<adTime*10){adCount+=1;
if (ie){documentWidth =document.body.offsetWidth/2+document.body.scrollLeft-20;
documentHeight =document.body.offsetHeight/2+document.body.scrollTop-20;}
else if (ns){documentWidth=window.innerWidth/2+window.pageXOffset-20;
documentHeight=window.innerHeight/2+window.pageYOffset-20;}
else if (w3){documentWidth=self.innerWidth/2+window.pageXOffset-20;
documentHeight=self.innerHeight/2+window.pageYOffset-20;}
adDiv.left=documentWidth-100;adDiv.top =documentHeight-0;
setTimeout("showAd()",100);}
}
function closeAd(){
if (ie||w3)
adDiv.display="none";
else
adDiv.visibility ="hide";
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>
<body background="../images/bg2.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div id="sponsorAdDiv" style="visibility:hidden; left: 2px; top: 15px; width: 197px; height: 13px">
<table width="200" height="15" bgcolor="#0099cc" border=0 cellspacing=1>
<tr>
<td>
<table width="100%" height="100%" border=0 cellspacing=0>
<tr bgcolor="#d2e9fe">
<td> 正在上传图片,请稍候...... </td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<form method="POST" action="upload2.asp" enctype="multipart/form-data" name="uppic" onsubmit="return(mysubmit(this));" style="margin-top: 0; margin-bottom: 6" >
<script>
var img=null;
var maxsize = 100; //定义允许文件的大小,单位KB,请根据需要自行修改!
function s()
{
if(img)img.removeNode(true);
img=document.createElement("img");
img.style.position="absolute";
img.style.visibility="hidden";
img.width = 0;
img.height = 0;
img.attachEvent("onreadystatechange",orsc);
img.attachEvent("onerror",oe);
document.body.insertAdjacentElement("beforeend",img);
img.src=uppic.inp.value;
}
function oe()
{
alert("此文件非图片文件");
uppic.submit.disabled=true;
}
function orsc()
{
if(img.readyState!="complete")return false;
if(img.fileSize/1024>maxsize)
{
uppic.submit.disabled=true;
alert("抱歉!您选择的文件为 "+Math.round(img.fileSize/1024,2)+" KB,超过了程序"+maxsize+" KB 的限制!");
}
else
uppic.submit.disabled=false;
}
</script>
<p style="margin-top: 0; margin-bottom: 0">
<input id="inp" type=file name="sf_upfile" size="25" class="text" onchange="s()" >
<input type="submit" name="submit" value="上 传 图 片" class="text" >
<input type="hidden" name="boardid" value="">
</p>
</form>
</body></html>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询