%
On Error Resume Next
dim conn 'database connection object
dim rs 'recordset
dim strSQL 'sql query
dim endline
'set endline
endline = chr(10)
'create the connection object
set conn = Server.CreateObject("ADODB.Connection")
'open the connection
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\home\hnt7c211\legacy\iha3skj42as9dh.mdb;"
'create a recordset
set rs = Server.CreateObject("ADODB.Recordset")
if Request.ServerVariables("REQUEST_METHOD") = "POST" then
'create an instance of the upload and jpg objects
Set Upload = Server.CreateObject("Persits.Upload")
Set Jpeg = Server.CreateObject("Persits.Jpeg")
'Limit file size to 350Kb, will throw an exception if file is larger
Upload.SetMaxSize 358400, True
'Save to memory. Path parameter is omitted
Count = Upload.Save
'get the file from the form
Set File = Upload.Files("image")
'if there is something there
if Not File Is Nothing then
'if the file is an image file
if File.ImageType <> "UNKNOWN" then
'we are going to open read only first
rs.LockType = adLockReadOnly
'check whether this file already exists using MD5 hash
strSQL = "SELECT * FROM Images WHERE hash='" & File.MD5Hash & "'"
rs.Open strSQL, conn
If Not rs.EOF Then
Session("responseString") = "That file already exists in the database!
" &_
"Back to Pictures"
'redirect to form_submit
Response.Redirect "form_submit.asp"
End If
rs.Close
'set rs properties
rs.CursorType = adOpenDynamic 'to move dynamically through rs
rs.LockType = adLockOptimistic 'to lock the recordset while updating
'reset the sql string
strSQL = "SELECT * FROM Images"
'run the query
rs.Open strSQL, conn
'add a new record
rs.AddNew
'now add the fields
rs("image_blob") = File.Binary
rs("filename") = File.FileName
rs("filesize") = File.Size
rs("hash") = File.MD5Hash
rs("credit") = Upload.Form("credit")
rs("caption") = Upload.Form("caption")
rs("approved") = ""
'open the image from the uploaded file
Jpeg.OpenBinary Upload.Files("image").Binary
'resize preserving aspect ratio
dim L
L = 120
If jpeg.OriginalWidth > jpeg.OriginalHeight Then
jpeg.Width = L
jpeg.Height = jpeg.OriginalHeight * L / jpeg.OriginalWidth
Else
jpeg.Height = L
jpeg.Width = jpeg.OriginalWidth * L / jpeg.OriginalHeight
End If
'add the thumbnail blob
rs("thumbnail_blob") = Jpeg.Binary
'write to the database
rs.Update
'close rs
rs.Close
'reset variables
set rs = Nothing
set conn = Nothing
Session("responseString") = "Your file has been uploaded to the web site. After an administrator " &_
"approves it, your picture will appear on the main page.
" &_
"Back to Pictures"
'send an email notifying admins of new pics
dim message
set message = CreateObject("CDO.Message")
message.Subject = "New picture posted to the Legacy Cruise II Website"
message.To = "dave@daveberlin.com"
message.From = "webmaster@daveberlin.com"
message.TextBody = "A new picture has been uploaded for your approval. " &_
"Log in to see the image."
message.Send
set message = Nothing
'not an image file
else
Session("responseString") = "That file does not appear to be an image. Please try again.
" &_
"Back to Pictures"
end if
'no file attached
else
Session("responseString") = "No file was selected! Please select a file to upload.
" &_
"Back to Pictures"
end if
' 8 is the number of "File too large" exception
If Err.Number = 8 Then
Session("responseString") = "Your file is too large. Please resize the image " &_
"so that it's 350KB or less.
" &_
"Back to Pictures"
Else
If Err <> 0 Then
Session("responseString") = "An error occurred. Make sure that you are trying to " &_
"upload an image file 350KB or less in size.
" &_
"Back to Pictures"
End If
End If
'redirect to form_submit
Response.Redirect "form_submit.asp"
end if
%>
|
|||||||||||
Legacy Cruise II departs in |
|||||||||||
Home | Register & Vote | History | Attendees | Pictures | Guestbook | Links | Feedback | ||||
Account Management
Email Newsletter
Voting Results
Copyright © 2005 Legacy Cruise Productions. All Rights Reserved.