ASP实现上传图片自动压缩图片大小
来源:风之相随'S BLOG 发布时间:2010-01-25 12:47:00
<!-- #include file="conn.asp" -->
<!--#include file="upload.inc"-->
<%'on error resume next%>
<%
dim upload,file,formName,formPath,iCount,filename,fileExt,i,mima,password
set upload=new upload_5xSoft '建立上传对象
name=upload.form("name")
formPath="../../uploadpic/"&Request.Cookies("login")("userName")&"/"'上传相对目录
userFileName=request.Cookies("login")("userName")'建立企业图片保存目录
CreateFolder(Server.MapPath("../../uploadpic/"&userFileName)) '建立企业文件夹
CreateFolder(Server.MapPath("../../uploadpic/"&userFileName&"/s")) '建立小图存放路径
CreateFolder(Server.MapPath("../../uploadpic/"&userFileName&"/b")) '建立小图存放路径
if right(formPath,1)<>"/" then formPath=formPath&"/"
for each formName in upload.file '列出所有上传了的文件
set file=upload.file(formName) '生成一个文件对象
if file.filesize<0 then
response.Write("请选择上传的文件")
response.end
end if
if file.filesize>500000 then
response.Write("文件不得超过500Kb")
response.end
end if
fileExt=lcase(right(file.filename,4))
if fileEXT<>".gif" and fileEXT<>".jpg" and fileEXT<>".png" then
response.Write("只允许上传gif,jPG,png文件!")
response.end
end if
Dim Jpeg
FilePath=Server.MapPath("./")'设置上传目录位置
FilePath=Req(FilePath &"/"&formPath)
Set Jpeg = Server.CreateObject("Persits.Jpeg")
If -2147221005=Err then
response.Write("没有ASPJPEG组件请安装")
Response.End()
End If
ranNum=int(900*rnd)+100
filenamett=file.FileName
filenamet=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&fileExt
filename=Req(filepath&filenamet)
filesize=file.filesize
if file.FileSize>0 then '如果 FileSize > 0 说明有文件数据
file.SaveAs filename '保存文件
else
response.redirect "info.asp?info=文件错误!"
response.Write("文件错误")
response.end
end if
'图片水印功能开始
Jpeg.Open filename
Jpeg.Canvas.Font.Color = &HFFFFFF
Jpeg.Canvas.Font.Family = "Arial" 'family设置字体
Jpeg.Canvas.Font.Bold = True '是否设置成粗体
Jpeg.Canvas.Font.Size = 16 '字体大小
Jpeg.Canvas.Font.Quality = 2'输出质量
Jpeg.Canvas.Print Jpeg.width-150, Jpeg.height-23, "WWW.2007LJFW.COM"
'Jpeg.Save filename'需要水印保留这句即可
'图片水印功能结束
set file=nothing
Jpeg.Open (filename)
'开始变更所有文件扩展名为jpg
filenamelen=len(filenamet)
filenamelen=filenamelen-4
filenamet1=filenamet
filenamet=left(filenamet,filenamelen)
filenamet=filenamet&".jpg"
'结束文件名变更
'开始判断哪边为长边,以长边进行缩放
imgWidth=Jpeg.OriginalWidth
imgHeight=Jpeg.OriginalHeight
if imgWidth>=imgHeight and imgWidth>=150 then
Jpeg.Width=150
Jpeg.Height=Jpeg.OriginalHeight/(Jpeg.OriginalWidth/150)
end if
if imgHeight>imgWidth and imgHeight>200 then
Jpeg.Height=200
Jpeg.Width=Jpeg.OriginalWidth/(Jpeg.OriginalHeight/200)
end if
'结束判断
'ImgObj.SaveFile(FilePath & "small_" & filenamet)
'end if
'ImgObj.Free
'Set ImgObj = nothing
Jpeg.Sharpen 1, 130
Jpeg.Save (FilePath & "/s/"&filenamet)
'写入数据库
yy=year(date)
mm=right("00"&month(date),2)
dd=right("00"&day(date),2)
idate=yy & "-" & mm & "-" & dd & " "
xx=right("00"&hour(time),2)
ff=right("00"&minute(time),2)
mm=right("00"&second(time),2)
itime=xx & ":" & ff & ":" & mm
itime=idate&itime
photourlb=formPath & filenamet1
'if imgwidth<320 and imgheight<240 then
photourls=formPath & "s/"&filenamet
'else
'photourls=photourlb
'end if
name=upload.form("name")
rs.open "SMT_cp",conn_p,1,3
rs.addnew
rs("name")=trim(upload.form("name"))
rs.update
rs.close
next
set upload=nothing
conn.close
set conn=nothing
conn_p.close
set conn_p=nothing
response.Redirect("add_products.asp?action=ok")
Function Req(Str)
If IsEmpty(Str) Then Exit Function
Str = Lcase(Str)
do
A_len=len(Str)
Str = Replace(Str,Chr(0),"")
Str = Replace(Str,"asp","")
Str = Replace(Str,"asa","")
Str = Replace(Str,"aspx","")
Str = Replace(Str,"cer","")
Str = Replace(Str,"cdx","")
Str = Replace(Str,"htr","")
Str = Replace(Str,"asax","")
Str = Replace(Str,"ascx","")
Str = Replace(Str,"ashx","")
Str = Replace(Str,"asmx","")
Str = Replace(Str,"axd","")
Str = Replace(Str,"vsdiso","")
Str = Replace(Str,"rem","")
Str = Replace(Str,"soap","")
Str = Replace(Str,"config","")
Str = Replace(Str,"cs","")
Str = Replace(Str,"csproj","")
Str = Replace(Str,"vb","")
Str = Replace(Str,"vbproj","")
Str = Replace(Str,"webinfo","")
Str = Replace(Str,"licx","")
Str = Replace(Str,"resx","")
Str = Replace(Str,"resou","")
Str = Replace(Str,"jsp","")
Str = Replace(Str,"php","")
Str = Replace(Str,"cgi","")
str = Replace(str," ","")
str = Replace(str,"%5C","")
str = Replace(str,"%2F","")
str = Replace(str,"asp","")
str = Replace(str,"asa","")
str = Replace(str,"cer","")
str = Replace(str,"cdx","")
str = Replace(str,"mdb","")
str = Replace(str,"hrt","")
str = Replace(str,"aspx","")
str = Replace(str,"php","")
str = Replace(str,"jsp","")
str = Replace(str,"'","")
loop until A_len=len(Str)
Req=Str
End Function
Function CreateFolder(Filepath)
Dim fso, f
on error resume next
Set fso = CreateObject("Scripting.FileSystemObject")
if not fso.FolderExists(Filepath) then
Set f = fso.CreateFolder(Filepath)
set f = Nothing
end if
set fso = Nothing
End Function
%>
猜你喜欢
- SQL Server所谓的分布式查询(Distributed Query)是能够访问存放在同一部计算机或不同计算机上的SQL Server或
- 组合集总计: group by with rollup/cube grouping sets 子查询按执行方式分:标准子查询、关联子查询 标
- 阅读之前:在看文章具体内容之前,希望你可以 先打开IE8,打开http://www.taobao.com,然后在地址栏里输入:javascr
- 用DIV+CSS可以作出很多不同形状的角形;以下我只写了几个;CSS没有优化;是为了让大家看得更清一些;以下是一些小三角的形状:这是第一个小
- 引伸阅读解读absolute与relativeposition:relative/absolute无法冲破的等级定位一直是WEB标准应用中的
- 或许你已经看过很多关于CSS3动画的技术,包括前端观察之前发表的一些,那么现在就情看一看CSS3动画的魅力吧。这里是一辑47个令人瞠目结舌的
- 许多网页开发者想从ASP.NET 页面传递一个值到另一个页面(比如从一个框架frame页面到一个弹窗页面)。看了代码就明白了。呵呵。(一)向
- 这是我在做的一个游戏的半成品,整理了一下发出来.原理:通过更新变换矩阵来记录转动(函数remx()).利用矩阵计算出转动后的正方体顶点坐标,
- 试了一下,xmlDoc.save()行不同,就试着用fso做了出来。整理一下,供大家discuss。由于用js操作本地xml文件之后save
- 网站可用性是任何网站的基本要素,而可用的导航更是网站所必需的要素之一。导航决定了用户如何与网站进行交互。如果没有了可用的导航,那么网站内容就
- 用QQ聊过天的朋友都对它的自动隐藏窗口功能爱不释手,它可以使窗口显得清爽整洁而且富有动感,笔者的几个朋友都想在自己的网页中加入类似的东东,经
- [摘要]了解如何充分利用SQL Server 2000的全文搜索功能。本文包含有关实现最大吞吐量和最佳性能的几点提示和技
- InstrRev描述:返回某字符串在另一个字符串中出现的从结尾计起的位置。语法:InstrRev(string1, string2
- 在安装好MYSQL ODBD的驱动程序后,应如何建立ASP文件连接数据库?我们有两种方法:一种是在ODBC数据源中建立一个DSN。具体方法是
- 对于一个内容页的文章来说,如果这个文章内容过长或是其中有分类(排行),那么进行分页阅读无疑是最好的选择。如果一个文章内容不涉及分类,比如小说
- 在一般的情况下,使用批量fetch的几率并不是很多,但是Oracle提供了这个功能我们最好能熟悉一下,说不定什么时候会用上它。declare
- 今日一同时问我,new Date(Date(str))这段代码什么意思?我一看就晕了,一个new Date 一个Date这是什么意思?这函数
- 你的主页或者你管理的网站有各种密码需要保护,把密码直接放在数据库或者文件中存在不少安全隐患,所以密码加密后存储是最常见的做法。在ASP.NE
- W3C发布了WCAG 2.0提案(Web Content Accessibility Guidelines 网页内容无障碍指南),大概为了实
- 【译者的话】 网页上的小广告(banner)已经成为一种宣传推广的重要形式,但这些小广告除了版面细小外,图象的表现还受到象素较低等其它因素影