Today in the Webmaster station to see a netizen to write the photo album program, the function is quite simple, see he used the aspjpeg to generate thumbnails, not to recall using aspupload upload, so spent one hours to perfect his code.
The following code has a simple comment, if you do not understand, please look at AspJpeg and AspUpload documentation (E, hope to have psychological preparation), can not understand the ask me.
Here's the code:
Copy Code code as follows:
<%
If session ("admin") <> ' on ' then
Response.Redirect "Login.asp"
End If
%>
<!--#include file= "config.asp"-->
<!--#include file= "mdb/conn.asp"-->
<%
Set Upload = Server.CreateObject ("Persits.upload")
Filepath=server.mappath (".")
Count = Upload.Save (filepath&bigphotopath) ' Big picture
Smallfilepath=filepath & Smallphotopath
For each File in Upload.files
Set Jpeg = Server.CreateObject ("Persits.jpeg")
Jpeg.open (File.path)
bigfp=bigphotopath& (file.filename) ' Large graph relative path
sfp=smallphotopath& "S_" & (file.filename) ' Small map relative path
Filesize=file.size ' ready to write to database
' Start to judge which side is the long edge, zoom with the long edge, and generate a small figure
Imgwidth=jpeg.originalwidth
Imgheight=jpeg.originalheight
If Imgwidth>=imgheight and imgwidth>120 then
jpeg.width=150
jpeg.height=jpeg.originalheight/(jpeg.originalwidth/150)
End If
If Imgheight>imgwidth and imgheight>113 then
jpeg.height=113
jpeg.width=jpeg.originalwidth/(jpeg.originalheight/113)
End If
Jpeg.sharpen 1, 130
Jpeg.save (smallfilepath& "S_" &file.filename)
' Add a watermark to the larger image (only large image watermark)
Jpeg.open Server.MapPath ("&BigFP&")
Jpeg.Canvas.Font.Color = &hff0000
Jpeg.Canvas.Font.Family = "Courier New"
Jpeg.Canvas.Pen.Color = &h000000
Jpeg.Canvas.Pen.Width = 2
Jpeg.Canvas.Brush.Solid = False
Jpeg.Canvas.Font.BkMode = "Opaque" Handles smoothing
Jpeg.Canvas.PrintText, "www.LuanLuan.cn"
' Jpeg.Canvas.DrawBar 1, 1, 100, 100
Jpeg.save Server.MapPath (BIGFP)
Next
strsql= insert INTO Desktop ([Name],typeid,zhuanti,jj,[time],imgh,imgw,filesize,url,surl) VALUES (' & Upload.form ("name") & "', '" &upload.form ("typeID") & "', '" &upload.form ("Zhuanti") & "', '" & Upload.form ("Photointro") & "', '" &now () & "', '" &imgheight& "', '" &imgwidth& "', '" & FileSize & "', ' &BigFP&" ', ' "&SFP&" "
Conn.execute strSQL
Set Upload=nothing ' Delete Object
Typeid=request.querystring ("typeID")
Response.Write "<script language=javascript>alert (' File upload success, return! ');"
Response.Write "This.location.href= ' addfile.asp?typeid=" &typeid& "';</script>"
function HTMLEncode2 (fstring)
fstring = Replace (fstring, CHR (13), "")
fstring = Replace (fstring, CHR (a) & CHR (a), "</P><P>")
fstring = Replace (fstring, CHR (), "<BR>")
HTMLEncode2 = fstring
End Function
%>