asp 上传图片 成比例缩小 并且可以设置图片的质量

<%
dim arr(3)
dim upload,file,formName,formPath,iCount,filename,fileExt,i
set upload=new upload_5xSoft ''建立上传对象
      
formPath="../upImgFile/"     '图片存放的路径:product目录下的uploadimages文件夹       ''在目录后加(/)

''列出所有上传了的文件
    for each formName in upload.file
      set file=upload.file(formName)
   if file.filesize>0 then
      if file.filesize>10000000 then
  response.write "<font size=2>图片大小超小了限制[<a href=# οnclick=history.go(-1)>重新上传</a>]</font>"
  response.end
      end if
   fileExt=lcase(right(file.filename,4))
   if fileExt<>".jpg" then
         response.write "<font size=2>文件格式限制[<a href=# οnclick=history.go(-1)>请重新上传</a>]</font>"
         response.end
      end if
end if
      
filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&file.FileName

    if file.FileSize>0 then         ''如果 FileSize > 0 说明有文件数据
       file.SaveAs Server.mappath(formpath&filename)   ''保存文件

' 图片位置
dim PhotoPath
PhotoPath = Server.MapPath(formpath&filename)
'缩小大图
call OKbigpic(PhotoPath)

       'response.write file.FilePath&file.FileName&"("&file.FileSize&") => "&formPath&File.FileName&"上传成功<br>"
       response.write "上传成功 <a href=# οnclick=history.go(-1)>请返回</a>" 

    end if
set file=nothing
next
set upload=nothing
Response.Write "<script>parent.add.P_url.value='"&FileName&"'</script>"

sub OKbigpic(FileName)
Dim bigpic,bigpicPath,fss
Set bigpic = Server.CreateObject("Persits.Jpeg")
set fss=createobject("scripting.filesystemobject")
' 设置图片质量
bigpic.Interpolation=2   
bigpic.Quality=90   
' 图片位置
if fss.fileExists(FileName) then
bigpic.Open FileName


'下面是按比例缩放
n_MaxWidth=900
n_MaxHeight=1500

  '按比例取得缩略图宽度和高度
  Dim n_OriginalWidth, n_OriginalHeight '原图片宽度、高度
  Dim n_BuildWidth, n_BuildHeight '缩略图宽度、高度
  Dim div1, div2
  Dim n1, n2
  '修改Jpeg
  n_OriginalWidth = bigpic.Width
  n_OriginalHeight = bigpic.Height
  div1 = n_OriginalWidth / n_OriginalHeight
  div2 = n_OriginalHeight / n_OriginalWidth
  n1 = 0
  n2 = 0
  If n_OriginalWidth > n_MaxWidth Then
   n1 = n_OriginalWidth / n_MaxWidth
  Else
   n_BuildWidth = n_OriginalWidth
  End If
  If n_OriginalHeight > n_MaxHeight Then
   n2 = n_OriginalHeight / n_MaxHeight
  Else
   n_BuildHeight = n_OriginalHeight
  End If
  If n1 <> 0 Or n2 <> 0 Then
   If n1 > n2 Then
    n_BuildWidth = n_MaxWidth
    n_BuildHeight = n_MaxWidth * div2
   Else
    n_BuildWidth = n_MaxHeight * div1
    n_BuildHeight = n_MaxHeight
   End If
  End If

  '指定宽度和高度生成
  bigpic.Width = n_BuildWidth
  bigpic.Height = n_BuildHeight
  
' 保存文件
bigpic.Save (FileName)
' 注销对象
Set bigpic = Nothing


end if
end sub 
%>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一、简介 自从接触ASP就开始接触上传,看过一些上传类,但是总感觉封装的还是不够简单,因此自己尝试写一个能够用最少最简单的代码实现各种上传方式的上传类。在学校期间就开始写,一点点的完善、优化,到现在的版本,现在的版本能适应各种上传方式。上 传类的主要的功能如下: 1、自由设置最大上传大小、单文件最大上传大小 2、自由设置允许上传的文件类型 3、可设置文本的编码,以适应各种上传环境 4、内置进度条,用户可选择开启和关闭 5、多种错误状态处理 6、多种文件保存方式:原文件名、随机文件名、用户自定义文件名 7、自由选择是否覆盖已存在文件 8、完整保存表单数据,支持同名表单,不支持同名文件域 注意: 1、特别注意Form一定要加上enctype="multipart/form-data"属性,method属性值必须是post,否则上传会出错 2、request.form()方法获取数据失效,请使用UpLoad.forms() 3、上传前请确认保存文件的文件夹有读写权限,若不可写则会出现"文件无法写入"错误,解决方法 http://dev.mo.cn/show.asp?id=81 二、调用方法 1、无组件类的调用方法: Dim Upload set Upload = new AnUpLoad 2、组件的调用方法: Dim Upload Set Upload = server.CreateObject("Anasp.Anupload") 注意:上传属性的设置必须在调用Upload.GetData()之前。 简单调用示例: Dim Upload set Upload=new AnUpLoad 'Set Upload = server.CreateObject("Anasp.Anupload") Upload.SingleSize=1024*1024*1024 '设置单个文件最大上传限制,按字节计;默认为不限制 Upload.MaxSize=1024*1024*1024 '设置最大上传限制,按字节计;默认为不限制 Upload.Exe="bmp|rar|pdf|jpg|gif" '设置合法扩展名,以|分割 Upload.Charset="gb2312" '设置文本编码,默认为gb2312 Upload.openProcesser=false '禁止进度条功能,如果启用,需配合客户端程序 Upload.GetData() '获取并保存数据,必须调用本方法

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值