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
%>


猜你喜欢
- 因为做项目中间有一个很小的环节需要这个功能,所以就写了一个简单的小函数,下面是具体实现:#!usr/bin/env python#encod
- 1.装饰器通用模型def wrapper(fn): def inner(*args, **kwargs):&nbs
- 前言在两种python循环语句的使用中,不仅仅是循环条件达到才能跳出循环体。所以,在对python函数进行阐述之前,先对跳出循环的简单语句块
- 就目前互联网上大小网站而言,大部分都是采用ASP+ACCESS/SQL Server或者PHP+MySQL来编写;事实上,ASP和MySQL
- mysql主从搭建环境:ubuntu20.04.1,mysql:8.0.22。主:192.168.87.3备:192.168.87.6安装数
- 目录Python的引入变量的引入为什么要有变量定义变量常量引入常量池引入Python解释器Python变量存储机制Python垃圾回收机制引
- 写在前面周日下午在家学习,看到一个关于切片的问题,在网上找了一些资料,做个总结。上代码func main() {sl := make([]i
- 最近,我加入了Cloudera,在这之前,我在计算生物学/基因组学上已经工作了差不多10年。我的分析工作主要是利用Python语
- 一、环境设置第一步引入必须的各类包import osimport tkinterimport tkinter.filedialogimpor
- 具体如下: 1>如我们知道开始时间,要加减一个时间,得出一个结果时间,可以用以下代码 $time1='2008-10-1 12
- 一、使用copula生成合成数据集(synthetic dataset)1. 三维数据描述建立一个三维数据表,查看三维数据的散点
- 1、什么是混淆矩阵深度学习中,混淆矩阵是ROC曲线绘制的基础,同时它也是衡量分类型模型准确度中最基本,最直观,计算最简单的方法。它可以直观地
- 首先,你得下载SocksiPy这个.解压出来之后里面会有一个socks.py文件.然后你可以把这个文件复制到python安装目录里面的Lib
- 前言最近在搞标准化巡检平台,通过 MySQL 的元数据分析一些潜在的问题。冗余索引也是一个非常重要的巡检目,表中索引过多,会导致表空间占用较
- 相信很朋友因为PyCharm最新激活码或激活补丁的安装参数每月都会失效而烦恼PyCharm最新激活码先分享个PyCharm最新激活码大家可以
- 在工作中遇到把DataGrid中绑定的后台数据库数据展示给用户时把负数变为0的小问题,现在记录下来。例子中数据表示这个样子的:-------
- 功能描述:1)使用tkinter设计程序界面;2)调用Windows API函数实现录音机和音乐播放器。参考代码:运行界面:总结以上所述是小
- 目录一、线程基础以及守护进程二、线程锁(互斥锁)三、线程锁(递归锁)四、死锁五、队列六、相关面试题七、判断数据是否安全八、进程池 &
- 前言前面几个章节我们学习了对于普通文件的操作,比如说文件的创建、复制粘贴、裁剪粘贴、文件名的重命名、删除等等。另外还学习了一些基本练习,如何
- 在GUI程序中,主线程也叫GUI线程,因为它是唯一被允许执行GUI相关操作的线程。对于一些耗时的操作,如果放在主线程中,就是出现界面无法响应