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

Legacy Cruise II departs in

Pictures from the Legacy Cruise

Use this form to upload your own pictures to the site. Please limit your photos to 350KB.

Image:
Photo Credit:
Photo Caption:
 
<% 'set the sql statement strSQL = "SELECT * FROM Images WHERE approved=""ON""" 'run the query and save to rs rs.Open strSQL, conn 'create the jpeg object 'Set Jpeg = Server.CreateObject("Persits.Jpeg") if rs.EOF then response.write( "" ) else 'get image from rs 'Jpeg.OpenBinary rs("thumbnail_blob").Value 'write results response.write( "" & endline) do while not rs.EOF response.write( "" ) for i = 1 to 5 if not rs.EOF then response.write( "" ) rs.MoveNext else response.write( "" ) end if next response.write( "" & endline ) loop end if 'now close connection rs.Close set rs = Nothing set conn = Nothing %>
No pictures uploaded