Forums
This topic is locked
ASP Image Upload and Display Problem
12 Oct 2002 18:55:00 Jim Moore posted:
I have used Pure ASP File Upload to upload an image to an Access Database and display it on an ASP page. The image is uploaded and placed in my the image column of my database table. The problem is that the browser is looking for the image in my root directory rather than in my image directory so it doesn't display. I don't know where to look to find and correct this problem. My Record set "test" shows the image in the right place on my table, The ASP Upload placed the image in the right image directory. Any help will be appreciated. The URL of the page with the image insert script is:www.standrewsbythebay.org/insert_image.asp.
The code on this page is as follows:
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/StAndrews.asp" -->
<!--#include file="ScriptLibrary/incPureUpload.asp" -->
<%
'*** Pure ASP File Upload -----------------------------------------------------
' Copyright (c) 2001-2002 George Petrov, www.UDzone.com
' Process the upload
' Version: 2.0.9
'------------------------------------------------------------------------------
'*** File Upload to: """AnnouncementImages""", Extensions: "GIF,JPG,JPEG,BMP,PNG", Form: insertImage, Redirect: "update2.asp", "file", "50", "over", "true", "", "" , "", "", "", "", "600", "", "300", "100"
Dim GP_redirectPage, RequestBin, UploadQueryString, GP_uploadAction, UploadRequest
PureUploadSetup
If (CStr(Request.QueryString("GP_upload"


on error resume next
Dim reqPureUploadVersion, foundPureUploadVersion
reqPureUploadVersion = 2.09
foundPureUploadVersion = getPureUploadVersion()
if err or reqPureUploadVersion > foundPureUploadVersion then
Response.Write "<b>You don't have latest version of ScriptLibrary/incPureUpload.asp uploaded on the server.</b><br>"
Response.Write "This library is required for the current page. It is fully backwards compatible so old pages will work as well.<br>"
Response.End
end if
on error goto 0
GP_redirectPage = "update2.asp"
Server.ScriptTimeout = 600
RequestBin = Request.BinaryRead(Request.TotalBytes)
Set UploadRequest = CreateObject("Scripting.Dictionary"

BuildUploadRequest RequestBin, """AnnouncementImages""", "file", "50", "over"
If (GP_redirectPage <> "" and not (CStr(UploadFormRequest("MM_insert"



If (InStr(1, GP_redirectPage, "?", vbTextCompare) = 0 And UploadQueryString <> ""

GP_redirectPage = GP_redirectPage & "?" & UploadQueryString
End If
Response.Redirect(GP_redirectPage)
end if
else
if UploadQueryString <> "" then
UploadQueryString = UploadQueryString & "&GP_upload=true"
else
UploadQueryString = "GP_upload=true"
end if
end if
' End Pure Upload
'------------------------------------------------------------------------------
%>
<%
' *** Edit Operations: (Modified for File Upload) declare variables
Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd
Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId
Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"

If (UploadQueryString <> ""

MM_editAction = MM_editAction & "?" & UploadQueryString
End If
' boolean to abort record edit
MM_abortEdit = false
' query string to execute
MM_editQuery = ""
%>
<%
' *** Update Record: (Modified for File Upload) set variables
If (CStr(UploadFormRequest("MM_update"



MM_editConnection = MM_StAndrews_STRING
MM_editTable = "StAndrewsTable1"
MM_editColumn = "UserID"
MM_recordId = "'" + UploadFormRequest("MM_recordId"

MM_editRedirectUrl = "update2.asp"
MM_fieldsStr = "FILE1|value"
MM_columnsStr = "GeneralPhotos|',none,''"
' create the MM_fields and MM_columns arrays
MM_columnsStr = FixColumnsForUpload(MM_fieldsStr,MM_columnsStr)
MM_fieldsStr = FixFieldsForUpload(MM_fieldsStr,MM_columnsStr)
MM_fields = Split(MM_fieldsStr, "|"

MM_columns = Split(MM_columnsStr, "|"

' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(UploadFormRequest(MM_fields(MM_i)))
Next
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And UploadQueryString <> ""

If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And UploadQueryString <> ""

MM_editRedirectUrl = MM_editRedirectUrl & "?" & UploadQueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & UploadQueryString
End If
End If
End If
%>
<%
' *** Update Record: (Modified for File Upload) construct a sql update statement and execute it
If (CStr(UploadFormRequest("MM_update"



' create the sql update statement
MM_editQuery = "update " & MM_editTable & " set "
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),","

MM_delim = MM_typeArray(0)
If (MM_delim = "none"

MM_altVal = MM_typeArray(1)
If (MM_altVal = "none"

MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none"

If (MM_formVal = ""

MM_formVal = MM_emptyVal
Else
If (MM_altVal <> ""

MM_formVal = MM_altVal
ElseIf (MM_delim = "'"

MM_formVal = "'" & Replace(MM_formVal,"'","''"

Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_editQuery = MM_editQuery & ","
End If
MM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_formVal
Next
MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId
If (Not MM_abortEdit) Then
' execute the update
Set MM_editCmd = Server.CreateObject("ADODB.Command"

MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> ""

Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset"

Recordset1.ActiveConnection = MM_StAndrews_STRING
Recordset1.Source = "SELECT * FROM StAndrewsTable1"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
<HTML>
<head>
<script language="JavaScript">
<!--
function checkFileUpload(form,extensions,requireUpload,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight) { //v2.09
document.MM_returnValue = true;
for (var i = 0; i<form.elements.length; i++) {
field = form.elements[i];
if (field.type.toUpperCase() != 'FILE') continue;
checkOneFileUpload(field,extensions,requireUpload,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight);
} }
function checkOneFileUpload(field,extensions,requireUpload,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight) { //v2.09
document.MM_returnValue = true;
if (extensions != '') var re = new RegExp("\.(" + extensions.replace(/,/gi,"|"




if (field.value == '') {
if (requireUpload) {alert('File is required!');document.MM_returnValue = false;field.focus();return;}
} else {
if(extensions != '' && !re.test(field.value)) {
alert('This file type is not allowed for uploading.\nOnly the following file extensions are allowed: ' + extensions + '.\nPlease select another file and try again.');
document.MM_returnValue = false;field.focus();return;
}
document.PU_uploadForm = field.form;
re = new RegExp(".(gif|jpg|png|bmp|jpeg)$","i"

if(re.test(field.value) && (sizeLimit != '' || minWidth != '' || minHeight != '' || maxWidth != '' || maxHeight != '' || saveWidth != '' || saveHeight != '')) {
checkImageDimensions(field,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight);
} }
}
function showImageDimensions(fieldImg) { //v2.09
var isNS6 = (!document.all && document.getElementById ? true : false);
var img = (fieldImg && !isNS6 ? fieldImg : this);
if (img.width > 0 && img.height > 0) {
if ((img.minWidth != '' && img.minWidth > img.width) || (img.minHeight != '' && img.minHeight > img.height)) {
alert('Uploaded Image is too small!\nShould be at least ' + img.minWidth + ' x ' + img.minHeight); return;}
if ((img.maxWidth != '' && img.width > img.maxWidth) || (img.maxHeight != '' && img.height > img.maxHeight)) {
alert('Uploaded Image is too big!\nShould be max ' + img.maxWidth + ' x ' + img.maxHeight); return;}
if (img.sizeLimit != '' && img.fileSize > img.sizeLimit) {
alert('Uploaded Image File Size is too big!\nShould be max ' + (img.sizeLimit/1024) + ' KBytes'); return;}
if (img.saveWidth != '') document.PU_uploadForm[img.saveWidth].value = img.width;
if (img.saveHeight != '') document.PU_uploadForm[img.saveHeight].value = img.height;
document.MM_returnValue = true;
} }
function checkImageDimensions(field,sizeL,minW,minH,maxW,maxH,saveW,saveH) { //v2.09
if (!document.layers) {
var isNS6 = (!document.all && document.getElementById ? true : false);
document.MM_returnValue = false; var imgURL = 'file:///' + field.value.replace(/\\/gi,'/').replace(/:/gi,'|').replace(/"/gi,'').replace(/^\//,'');
if (!field.gp_img || (field.gp_img && field.gp_img.src != imgURL) || isNS6) {field.gp_img = new Image();
with (field) {gp_img.sizeLimit = sizeL*1024; gp_img.minWidth = minW; gp_img.minHeight = minH; gp_img.maxWidth = maxW; gp_img.maxHeight = maxH;
gp_img.saveWidth = saveW; gp_img.saveHeight = saveH; gp_img.onload = showImageDimensions; gp_img.src = imgURL; }
} else showImageDimensions(field.gp_img);}
}
//-->
</script>
<title>Chip Havilmyer - Newsletter - Insert Image</title>
<link rel="stylesheet" href="file:///C|/Bay%20Info-Tech/Health%20Tech%20Plus.Com/newmanzone/0072224649_code/realty_asp/www/realty.css" type="text/css">
</head>
<BODY BGCOLOR="#FFFFFF">
<div align="center"><img src="file:///C|/Bay%20Info-Tech/Health%20Tech%20Plus.Com/newmanzone/0072224649_code/realty_asp/www/images/headers/insert-image.gif" width="350" height="40"><br>
<font size="2" face="Arial, Helvetica, sans-serif">Browse to a GIF or JPG image on your
computer <br>
and click "Upload Image."</font>
<form action="<%=MM_editAction%>" method="post" enctype="multipart/form-data" name="insertImage" onSubmit="checkFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',true,50,'','','','','','');return document.MM_returnValue">
<table width="300" border="0" cellspacing="0" cellpadding="5">
<tr>
<td> <table width="300" border="1" cellspacing="0" cellpadding="15" bordercolor="#000000">
<tr>
<td bgcolor="#d0dce0"> <div align="center">
<input name="FILE1" type=FILE onChange="checkOneFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',true,50,'','','','','','')" size=30>
</div></td>
</tr>
</table></td>
</tr>
<tr>
<td> <div align="center">
<input type=SUBMIT value="Upload Image" name="SUBMIT" class="button" onMouseover="this.className='buttonover'" onMouseout="this.className='button'">
</div></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="insertImage">
<input type="hidden" name="MM_recordId" value="<%= Recordset1.Fields.Item("UserID"

</form>
</div>
<div align="center">
<p><font size=1 face="Verdana, Arial, Helvetica, sans-serif"><i>NOTE: Insert
additional image upload instructions here.</i></font></p>
<p><i><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><img src="<%=(Recordset1.Fields.Item("GeneralPhotos"

</div>
</BODY>
</HTML>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
Replies
Replied 13 Oct 2002 00:14:43
13 Oct 2002 00:14:43 Jeremy Conn replied:
Sounds to me like you need to make sure "Save Full Path" is selected in the upload options inside Pure ASP Upload. That way it will hold the actual location, rather than just the filename resulting in your problem.
(DWMX|IIS5|WXP|ASP/VB)
*Connman21*
www.conncreativemedia.com
(DWMX|IIS5|WXP|ASP/VB)
*Connman21*
www.conncreativemedia.com