asp网站上传图片自动压缩图片大小代码,把以下代码修改成能够压缩图片的代码。 50
<html><head><metahttp-equiv="Content-Type"content="text/html;charset=gb2312"><title>上...
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>上传文件</title>
</head>
<script language="javascript">
function checkupload(){
if(document.upload_form.file.value ==""){
alert("没有选择要上传的文件");
return false;
}
}
</script>
<%
Response.Expires=0
if Request.TotalBytes then
set a=createobject("adodb.stream")
a.Type=1
a.Open
a.write Request.BinaryRead(Request.TotalBytes)
a.Position=0
b=a.Read
c=chrB(13)&chrB(10)
d=instrb(b,c)
e=instrb(d+1,b,c)
set f=createobject("adodb.stream")
f.type=1
f.open
a.Position=d+1
a.copyto f,e-d-3
f.Position=0
f.type=2
f.CharSet="GB2312"
g=f.readtext
f.Close
h=mid(g,instrRev(g,"\")+1,e)
h=mid(h,instrRev(h,"=")+2)
i=instrb(b,c&c)+4
j=instrb(i+1,b,leftB(b,d-1))-i-2
select case lcase(mid(h,InStrRev(h,".")+1))
case "gif"
hh =".gif"
case "jpg"
hh =".jpg"
case "png"
hh =".png"
case "bmp"
hh =".bmp"
case else
response.write "<script>alert('\n\n图片上传不成功:系统只支持gif和jpg格式的图片!请转换后再上传');location.href='upload.asp';</script>"
set f=Nothing
a.Close
set a=Nothing
response.End()
end select
f.Type=1
f.Open
a.Position=i-1
a.CopyTo f,j
filename=year(now)&"年"&month(now)&"月"&day(now)&"日"&hour(now)&minute(now)&second(now) &hh
f.SaveToFile Server.MapPath("images\"&filename),2
f.close
set f=Nothing
a.Close
set a=Nothing
Set db = Server.CreateObject("ADODB.Connection")
%><!--#include file="db.asp"--><%
set rs = server.CreateObject("adodb.recordset")
Sql="Select * From picture"
db.Errors.Clear
rs.open sql,db,2,3
if db.Errors.Count = 0 then
rs.addnew
rs("文件名")=filename
rs.update
tp_ID=rs("ID")
end if
rs.close
set rs=nothing
db.Close
Set db=Nothing
response.write "<script>alert('\n\n图片上传成功:继续上传');</script>"
%>
<script language="javascript">
parent.document.getElementById("tupian").innerHTML=parent.document.getElementById("tupian").innerHTML+"<p><img src='images/<%=filename%>' name='tp' id='tp<%=tp_ID%>' onClick='sqtupian(\"<%=tp_ID%>\")' title='单击可以删除此图片' width='200' height='200'><P>";
parent.document.getElementById("tj_tupian").value = parent.document.getElementById("tj_tupian").value + "<%=tp_ID%>"+",";
</script>
</script>
<%end if%>
<body style="float:left; margin-left:0cm; margin-top:0cm; padding-left:0cm; padding-top:0cm">
<form name="upload_form" enctype="multipart/form-data" method="post" action="upload.asp" onsubmit="return(checkupload())">
<input type="file" name="file"> <input type="submit" name="Submit" value="上传图片">
</form>
</body>
</html> 展开
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>上传文件</title>
</head>
<script language="javascript">
function checkupload(){
if(document.upload_form.file.value ==""){
alert("没有选择要上传的文件");
return false;
}
}
</script>
<%
Response.Expires=0
if Request.TotalBytes then
set a=createobject("adodb.stream")
a.Type=1
a.Open
a.write Request.BinaryRead(Request.TotalBytes)
a.Position=0
b=a.Read
c=chrB(13)&chrB(10)
d=instrb(b,c)
e=instrb(d+1,b,c)
set f=createobject("adodb.stream")
f.type=1
f.open
a.Position=d+1
a.copyto f,e-d-3
f.Position=0
f.type=2
f.CharSet="GB2312"
g=f.readtext
f.Close
h=mid(g,instrRev(g,"\")+1,e)
h=mid(h,instrRev(h,"=")+2)
i=instrb(b,c&c)+4
j=instrb(i+1,b,leftB(b,d-1))-i-2
select case lcase(mid(h,InStrRev(h,".")+1))
case "gif"
hh =".gif"
case "jpg"
hh =".jpg"
case "png"
hh =".png"
case "bmp"
hh =".bmp"
case else
response.write "<script>alert('\n\n图片上传不成功:系统只支持gif和jpg格式的图片!请转换后再上传');location.href='upload.asp';</script>"
set f=Nothing
a.Close
set a=Nothing
response.End()
end select
f.Type=1
f.Open
a.Position=i-1
a.CopyTo f,j
filename=year(now)&"年"&month(now)&"月"&day(now)&"日"&hour(now)&minute(now)&second(now) &hh
f.SaveToFile Server.MapPath("images\"&filename),2
f.close
set f=Nothing
a.Close
set a=Nothing
Set db = Server.CreateObject("ADODB.Connection")
%><!--#include file="db.asp"--><%
set rs = server.CreateObject("adodb.recordset")
Sql="Select * From picture"
db.Errors.Clear
rs.open sql,db,2,3
if db.Errors.Count = 0 then
rs.addnew
rs("文件名")=filename
rs.update
tp_ID=rs("ID")
end if
rs.close
set rs=nothing
db.Close
Set db=Nothing
response.write "<script>alert('\n\n图片上传成功:继续上传');</script>"
%>
<script language="javascript">
parent.document.getElementById("tupian").innerHTML=parent.document.getElementById("tupian").innerHTML+"<p><img src='images/<%=filename%>' name='tp' id='tp<%=tp_ID%>' onClick='sqtupian(\"<%=tp_ID%>\")' title='单击可以删除此图片' width='200' height='200'><P>";
parent.document.getElementById("tj_tupian").value = parent.document.getElementById("tj_tupian").value + "<%=tp_ID%>"+",";
</script>
</script>
<%end if%>
<body style="float:left; margin-left:0cm; margin-top:0cm; padding-left:0cm; padding-top:0cm">
<form name="upload_form" enctype="multipart/form-data" method="post" action="upload.asp" onsubmit="return(checkupload())">
<input type="file" name="file"> <input type="submit" name="Submit" value="上传图片">
</form>
</body>
</html> 展开
1个回答
展开全部
要压缩图片大小的必须要有组件,就是服务器要支持这个组件才可以。
下面介绍一个:
ASPJPEG是一款功能相当强大的图象处理组件,用它可以轻松地做出图片的缩略图和为图片加上水印功能。
实际怎么样我没有用过这个组件不做评价,你可以网上找找。
下面介绍一个:
ASPJPEG是一款功能相当强大的图象处理组件,用它可以轻松地做出图片的缩略图和为图片加上水印功能。
实际怎么样我没有用过这个组件不做评价,你可以网上找找。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询