DW8 Uploading Images Loop to Insert into mdb
Posted on 2007-10-21
This is actually working fine, but I need to make a change that has me stumped....
I have a form on a an ASP VB page that has three fields for images (A) below.
On the following page I have some uploas (ASP Upload) code as in (B) below.
Now as it is it's fine, but I have now added a further field to the image table which is a boolean - for 'featured image' this willl show true for the FIRST or only (if one) image that is loaded and false for the subsequent images of the three. This is so that in the produduct list pages, the main image shows, and in the detail page for the product there is an option to view the additional images.
I have managed to do this before but was storing the images in the database itsel (not a very good idea, and will be coming back to haunt me/us one day soon :) So my previous code isn't helping.
I guess I need to lose or adapt the loop to add 'Featured' first time round?
Any ideas? Let me know if I should paste up any more of the code, not that there is much.
Thanks a lot
<td align="left" class="labelText"><input name="FILE" type="file" id="FILE" size="40" /></td>
<td align="left" class="formLabelsSmall">Image 2:</td>
<td align="left" class="labelText"><input name="FILE2" type="file" id="FILE2" size="40" /></td>
<td align="left" class="formLabelsSmall">Image 3: </td>
<td align="left" class="labelText"><input name="FILE3" type="file" id="FILE3" size="40" />
Set Upload = Server.CreateObject("Persits.Upload")
<h1 align="center"> Image Upload Confirmation:</h1>
<div align="center" class="warning"><br />
For Each File in Upload.Files
' Obtain file name
Filename = file.Filename
' check if file exists in c:\upload under this name
If Upload.FileExists (Server.mapPath("../../databases/img/" & filename)) Then
Response.Write "WARNING:<br />Image named - " & File.Path & " - already exists.<br /> Please RENAME this image and load again via the additional images admin menu.<br /><br />"
' otherwise save file
File.SaveAs Server.mapPath("../../databases/img/" & File.Filename)
Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_MagicalRooms_STRING
MM_editCmd.CommandText = "INSERT INTO tblImages (ProdID, Image) VALUES (?, ?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 5, 1, -1, Upload.Form("frmprodid")) ' adDouble
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 202, 1, 255, Filename) ' adVarWChar