SA Upload SQL Database variable types (image upload and storage)
I am having trouble with the SA Upload utility. The following code used to work correctly. However, I lost my database and had to rebuild. Does anyone have any suggestions on what I may have wrong. I am not sure if I built my table to store the picture id's correctly. Maybe a field type or something.
- <form name="UpdatePropertyPicture" method="POST" action="UpdatePropertyPicture.asp"><p><strong><font size="5">Property Picture</font></strong><br>
-
</p>
-
<p><font face="Times New Roman"><b>Current Property Picture for this listing:</b></font></p>
-
<table border="0" cellpadding="0" width="100%" cols=4>
-
<td>
-
</td>
-
-
<%
-
Set rs = Server.CreateObject("ADODB.Recordset")
-
SQL = "Select list_id, PictureName"
-
SQL = SQL & " from tblDescr"
-
SQL = SQL & " where list_id = " & varlistid
-
-
'open the recordset
-
rs.Open SQL, cn
-
varPicture = rs("PictureName")
-
rs.close
-
cn.Close
-
%>
-
-
<tr>
-
<td width="1%"><input type="hidden" size="15" maxlength="15" name="txtlistid" value="<%=varlistid%>"></td>
-
<td width="12%" valign="top">
-
<%If varpicture = "" Then%>
-
No Picture
-
<%Else%>
-
<input type="checkbox" name="chkPropertyPicture" value="<%=varPicture%>">
-
<%=varPicture%>
-
<input TYPE="HIDDEN" Name="h<%=I%>" VALUE="<%=varPicture%>">
-
<%End If%>
-
</td>
-
<td width="25%" align="center">
-
<img src="images/Pictures/<%=varPicture%>" height="275" width="225" align="center"> </td>
-
<td width="25%">
-
<input TYPE="SUBMIT" NAME="btnUploadPicture" VALUE="Upload Property Picture">
-
</td>
-
</tr>
-
-
<tr>
-
<td></td>
-
<td align="center"><input type="submit" value="Delete" id="btnDelete" name="btnDelete"></td>
-
<td></td>
-
<td></td>
-
</tr>
-
-
</tr>
-
<td></td>
-
<td></td>
-
<td></td>
-
<td></td>
-
</tr>
-
-
</tr>
-
<td></td>
-
<td></td>
-
<%If Session("AddUpdatePic") = "Add" Then%>
-
<td align="center"><input type="submit" id="bntExitAdd" value="Continue to Unit Mix" name="bntExitAdd"> <input TYPE="Button" NAME="btnReload" VALUE="Reload Picture" onClick="javascript:location.reload();"></td>
-
<%Else%>
-
<td align="center"><input type="submit" id="bntExitUpdate" value="Return to Update Property" name="bntExitUpdate"> <input TYPE="Button" NAME="btnReload" VALUE="Reload Picture" onClick="javascript:location.reload();"></td>
-
<%End If%>
-
<td></td>
-
</tr>
-
</table>
-
-
</FORM>
And this is the response page for after the image is uploaded:
- <%
-
'Instanciate SA-FileUp
-
Set upl = Server.CreateObject("SoftArtisans.FileUp")
-
-
'Set the default path to store uploaded files.
-
'upl.Path = "d:\inetpub\wwwRoot\cartergroup\Images\Pictures" 'Use this path for WCDEV03
-
'upl.Path = "d:/inetpub/wwwroot/cartergroup.com/www/phase2/images/Pictures/" 'Use this path for TS
-
upl.Path = "d:/inetpub/wwwroot/kansascitycs.atempsite.com/www/falconbuilt/uploads/"
-
varlistid = session("listid")
-
%>
-
-
<%If upl.IsEmpty Then %>
-
The file that you uploaded was empty. Most likely, you did not specify a valid
-
filename to your browser or you left the filename field blank. Please try again.
-
-
<%ElseIf upl.ContentDisposition <> "form-data" Then %>
-
Your upload did not succeed, most likely because your browser
-
does not support Upload via this mechanism.
-
<br>
-
For Internet Explorer Users:
-
<UL>
-
<LI>For Windows 95 or Windows NT 4.0:
-
<UL>
-
<LI><A HREF="http://www.microsoft.com/ie/">Download</A> V3.02 or later of Internet Explorer
-
<LI><A HREF="http://www.microsoft.com/ie/download">Download</A> the File Upload Add-on
-
<LI>For further information, See Knowledge Base Article <A HREF="http://www.microsoft.com/kb/articles/Q165/2/87.htm">Q165287</A>
-
</UL>
-
<LI>For Windows 3.1, WFW 3.11 (Windows 16-bit), or Windows NT 3.51:
-
<UL><A HREF="http://www.microsoft.com/ie/">Download</A> V3.02A or later of Internet Explorer for 16-bit Windows
-
</UL>
-
</UL>
-
For Netscape Users:
-
<UL>
-
<LI><A HREF="http://home.netscape.com">Download</A> a version of Netscape Navigator or Communicator of 2.x or later
-
</UL>
-
For users of other browsers:
-
<UL>
-
<LI>Your browser must support a standard called RFC 1867. Please check with your browser vendor for
-
support of this standard.
-
</UL>
-
-
<%Else %>
-
<P><center>Your picture has been successfully transmitted to your listing.</center></P>
-
<%
-
on error resume next
-
-
dim strFilename
-
dim strExtension
-
dim strFilename2
-
-
strExtension = Mid(upl.UserFilename, InstrRev(upl.UserFilename, ".") + 1)
-
strFilename = "pic" & trim(varlistid) & "." & lcase(strExtension)
-
-
If strExtension = "jpg" or strExtension = "gif" Then
-
'--- Save file - use the listID as the filename with the extension of the original file
-
upl.SaveAs strfilename
-
Else
-
Err = 1
-
End If
-
-
If Err <> 0 Then %>
-
<H1><FONT COLOR="#ff0000">An error occurred when saving the file on the server.</FONT></H1>
-
Possible causes include:
-
<UL>
-
<LI>An incorrect filename was specified
-
<LI>File permissions do not allow writing to the specified area
-
<LI>Your picture has an extension other than .jpg or .gif
-
</UL>
-
Please check the SA-FileUp documentation for more troubleshooting information,
-
or send e-mail to <A HREF="mailto:info@softartisans.com">info@softartisans.com</A>
-
-
<%Else
-
'Response.Write("Upload saved successfully to " & upl.ServerName)
-
Response.Write("<center>Your picture has been saved successfully.</center>")
-
-
'Get current file extension
-
Set rs = Server.CreateObject("ADODB.Recordset")
-
SQL = "SELECT PictureName FROM tblDescr "
-
SQL = SQL & "WHERE list_id = " & varlistid
-
'open the recordset
-
rs.Open SQL, cn
-
-
If not rs.EOF Then
-
varSavPrevPic = rs("PictureName")
-
Else
-
varSavPrevPic = ""
-
End If
-
rs.close
-
-
If strExtension <> right(varSavPrevPic,3) Then
-
'strFilename2 = "d:\inetpub\wwwRoot\cartergroup\Images\Pictures\" & varSavPrevPic 'Use this path for WCDEV03
-
strFilename2 = "d:/inetpub/wwwroot/cartergroup.com/www/phase2/images/Pictures/" & varSavPrevPic 'Use this path for TS
-
-
'If user uploaded a logo with a different extension - it now needs to be removed from the logos directory
-
Set fso = CreateObject("Scripting.FileSystemObject")
-
Set MyFile = fso.GetFile(strFilename2)
-
MyFile.Delete
-
End If
-
-
Set rs = Server.CreateObject("ADODB.Recordset")
-
SQL = "UPDATE tblDescr "
-
SQL = SQL & "SET PictureName = '" & strFilename & "' "
-
SQL = SQL & "WHERE list_id = " & varlistid
-
'open the recordset
-
rs.Open SQL, cn
-
rs.close
-
cn.Close
-
End If%>