home *** CD-ROM | disk | FTP | other *** search
/ Practical Internet Web Designer 88 / PIWD88.iso / mac / contents / developer / tutorial_files / Pages94-95 / editalbum2.asp < prev    next >
Text File  |  2003-11-03  |  2KB  |  58 lines

  1. <%@LANGUAGE="VBSCRIPT"%>
  2. <%Option Explicit%>
  3. <%
  4. Dim Upload, uploadArray, fileName, newFileName, fso, imageTitle, imageDesc, conn, strSQL
  5. 'Set ASPUpload and grab file
  6. Set Upload = Server.CreateObject("Persits.Upload.1")
  7. Upload.SaveVirtual("/uploads")
  8. 'get real filename from end of path
  9. uploadArray = split((Upload.Files(1).Path),"\")
  10. fileName = uploadArray(ubound(uploadArray))
  11.  
  12. 'get form details
  13. imageTitle = Upload.Form("imageTitle")
  14. imageDesc = Upload.Form("imageDesc")
  15. 'remove single quotes from title and description
  16. imageTitle = Replace(imageTitle, "'", "''")
  17. imageDesc = Replace(imageDesc, "'", "''")
  18. 'make a new filename
  19. newFileName = Now() & fileName
  20. newFileName = Replace(newFileName, " ", "_")
  21. newFileName = Replace(newFileName, "/", "")
  22. newFileName = Replace(newFileName, "\", "")
  23. newFileName = Replace(newFileName, ":", "")
  24. 'rename file
  25. Set fso = CreateObject("Scripting.FileSystemObject")
  26. fso.MoveFile Server.MapPath("/uploads/" & fileName), Server.MapPath("/uploads/" & newFileName)
  27.     
  28. set fso = nothing
  29. set Upload = nothing
  30.  
  31. 'insert details into the database
  32. Set conn = Server.CreateObject("ADODB.Connection")
  33. conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  34.            "Data Source=F:\Databases\photoalbum.mdb;"  & _
  35.            "Jet OLEDB:Database"
  36. strSQL = "INSERT INTO tblImages (imageTitle, imageDesc, imageFilename) VALUES ('" & imageTitle & "','" & imageDesc & "','" & newFileName & "')"
  37. conn.execute(strSQL)
  38. %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  39.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  40.  
  41. <html>
  42. <head>
  43. <title>Thankyou for uploading your Photograph</title>
  44. <link rel="stylesheet" type="text/css" href="global.css" />
  45. </head>
  46.  
  47. <body>
  48. <div id="content">
  49. <h1>Upload Successful</h1>
  50. <p>Your file <strong><%=imageTitle%></strong> (<%=fileName%>) was successfully uploaded. Thank you.</p>
  51. <p><img src="/uploads/<%=newFileName%>" alt="<%=imageTitle%>" /></p>
  52.  
  53. <p><a href="editalbum.asp">Add another photograph</a></p>
  54. </div>
  55. </body>
  56. </html>
  57.  
  58.