Forums

This topic is locked

ASP Upload, SIP and insert record error

Posted 20 Mar 2003 19:26:59
1
has voted
20 Mar 2003 19:26:59 Josh Wagner posted:
I am creating an upload form where an image is uploaded, it is resized and thumbnailed, and then inserted into a database.. the images are uploaded and resized but the info is not added to the database. I have the Insert record behavior redirecting to a complete.asp page but it just comes up wih an internal server error when the form is submitted. If i hit refresh on the internal server error message, I get the 'form was submitted with the encode type wrong error. Code is below.. any help would be great. Thanks in advance.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../../../Connections/connEvents.asp" -->
<!--#include file="../../../ScriptLibrary/incResizeAddOn.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: """../../listings/"" & Session(""ListingID""", Extensions: "JPG", Form: FormUpload, Redirect: "", "path", "", "over", "true", "", "" , "", "", "", "", "900", "fileCopyProgress.htm", "300", "100"

Dim GP_redirectPage, RequestBin, UploadQueryString, GP_uploadAction, UploadRequest
PureUploadSetup

If (CStr(Request.QueryString("GP_upload") <> "" Then
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 = ""
Server.ScriptTimeout = 900

RequestBin = Request.BinaryRead(Request.TotalBytes)
Set UploadRequest = CreateObject("Scripting.Dictionary"
BuildUploadRequest RequestBin, """../../listings/"" & Session(""ListingID""", "path", "", "over"

If (GP_redirectPage <> "" and not (CStr(UploadFormRequest("MM_insert") <> "" or CStr(UploadFormRequest("MM_update") <> "") Then
If (InStr(1, GP_redirectPage, "?", vbTextCompare) = 0 And UploadQueryString <> "" Then
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
'------------------------------------------------------------------------------
%>
<%
' *** Smart Image Processor 1.0.7
If (CStr(Request.QueryString("GP_upload") <> "" Then
Dim RUF_Component, RUF_DotNetResize, RUF_path, RUF_ResizeImages, RUF_maxWidth, RUF_maxHeight, RUF_Quality, RUF_MakeThumb, RUF_Suffix, RUF_maxWidthThumb, RUF_maxHeightThumb, RUF_QualityThumb, RUF_RedirectURL
RUF_Component = "AUTO"
RUF_DotNetResize = "../../../ScriptLibrary/ResizeImage.aspx"
RUF_path = ""
RUF_ResizeImages = true
RUF_maxWidth = "500"
RUF_maxHeight = "500"
RUF_Quality = "80"
RUF_MakeThumb = true
RUF_Suffix = "_small"
RUF_maxWidthThumb = "100"
RUF_maxHeightThumb = "100"
RUF_QualityThumb = "70"
RUF_RedirectURL = ""
if RUF_ResizeImages then
ResizeUploadedFiles RUF_Component, RUF_DotNetResize, RUF_path, "", RUF_maxWidth, RUF_maxHeight, RUF_Quality, true
end if
if RUF_MakeThumb then
ResizeUploadedFiles RUF_Component, RUF_DotNetResize, RUF_path, RUF_Suffix, RUF_maxWidthThumb, RUF_maxHeightThumb, RUF_QualityThumb, false
end if
if RUF_RedirectURL <> "" then
Response.Redirect RUF_RedirectURL
end if
end if
%>
<%
' *** 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 <> "" Then
MM_editAction = MM_editAction & "?" & UploadQueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: (Modified for File Upload) set variables

If (CStr(UploadFormRequest("MM_insert") = "FormUpload" Then

MM_editConnection = MM_connEvents_STRING
MM_editTable = "Photo_Tbl"
MM_editRedirectUrl = "complete.asp"
MM_fieldsStr = "Photo_Name|value|ListingID|value"
MM_columnsStr = "Photo_Name|',none,''|PhotoID|none,none,NULL"

' create the MM_fields and MM_columns arrays
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 <> "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And UploadQueryString <> "" Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & UploadQueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & UploadQueryString
End If
End If

End If
%>
<%
' *** Insert Record: (Modified for File Upload) construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(UploadFormRequest("MM_insert") <> "" Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
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" Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none" Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none" Then MM_emptyVal = ""
If (MM_formVal = "" Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "" Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'" Then ' escape quotes
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_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & " values (" & MM_dbValues & ""

If (Not MM_abortEdit) Then
' execute the insert
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 <> "" Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>
<%
Dim rsListings__MMColParam
rsListings__MMColParam = "1"
If (Session("Region" <> "" Then
rsListings__MMColParam = Session("Region"
End If
%>
<%
Dim rsListings
Dim rsListings_numRows

Set rsListings = Server.CreateObject("ADODB.Recordset"
rsListings.ActiveConnection = MM_connEvents_STRING
rsListings.Source = "SELECT listing_id, affiliate_id, listing_state FROM Listing_Tbl WHERE listing_state = '" + Replace(rsListings__MMColParam, "'", "''" + "' ORDER BY listing_id DESC"
rsListings.CursorType = 0
rsListings.CursorLocation = 2
rsListings.LockType = 1
rsListings.Open()

rsListings_numRows = 0
%>
<%
Dim rsPhotos
Dim rsPhotos_numRows

Set rsPhotos = Server.CreateObject("ADODB.Recordset"
rsPhotos.ActiveConnection = MM_connEvents_STRING
rsPhotos.Source = "SELECT * FROM Photo_Tbl"
rsPhotos.CursorType = 0
rsPhotos.CursorLocation = 2
rsPhotos.LockType = 1
rsPhotos.Open()

rsPhotos_numRows = 0
%>
<%
Session("ListingID" = ""
Session("ListingID" = (rsListings.Fields.Item("listing_id".Value)
%>
<% If Session("ActiveUserLevel" < "800" then response.Redirect("/login/"%>
<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,"|".replace(/\s/gi,"" + "$","i";
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);}
}

function showProgressWindow(progressFile,popWidth,popHeight) { //v2.09
var showProgress = false, form, field;
for (var f = 0; f<document.forms.length; f++) {
form = document.forms[f];
for (var i = 0; i<form.elements.length; i++) {
field = form.elements[i];
if (field.type.toUpperCase() != 'FILE') continue;
if (field.value != '') {showProgress = true;break;}
} }
if (showProgress && document.MM_returnValue) {
var w = 480, h = 340;
if (document.all || document.layers || document.getElementById) {
w = screen.availWidth; h = screen.availHeight;}
var leftPos = (w-popWidth)/2, topPos = (h-popHeight)/2;
document.progressWindow = window.open(progressFile,'ProgressWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=' + popWidth + ',height='+popHeight);
document.progressWindow.moveTo(leftPos, topPos);document.progressWindow.focus();
window.onunload = function () {document.progressWindow.close();};
} }
//-->
</script>
<title>Site Administration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META HTTP-EQUIV="imagetoolbar" CONTENT="no">
<link href="../../layout/layout.css" rel="stylesheet" type="text/css">
<META HTTP-EQUIV="EXPIRES" CONTENT="0">
<meta name="title" content="CashTruck Real Estate Investments" />
<meta name="description" content="real estate, homes, investor, buy, houses, cash, cashtruck, Denali
Investment Group, estate, real, sell, investment, cashtruck.com,
mortgage, banks, no bank qualifying, Phoenix, Arizona, United States,
Alabama, Michigan, North Carolina, Virginia, Las Vegas, California,
Nevada, Texas" />
<meta name="keywords" content="real estate, homes, investor, buy, houses, cash, cashtruck, Denali" />
<meta name="author" content="Cash Truck" />
<meta name="copyright" content="Cash Truck 2002" />
<meta name="robots" content="ALL" />
<meta name="revisit-after" content="15 days" />
<meta name="document-type" content="Public" />
<meta name="document-rating" content="General" />
<meta name="document-state" content="Dynamic" />
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="761" border="1" cellpadding="0" cellspacing="0" bordercolor="#C2B6A3">
<tr>
<td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#D9D7CA"><img src="../../layout/layout_r1_c1.gif" width="243" height="45"></td>
<td bgcolor="#D9D7CA"><div align="right"><a href="/"><img src="../../layout/layout_r1_c4.gif" width="262" height="45" border="0"></a></div>
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="24%" background="../../layout/layout_r2_back.gif"><img src="../../layout/layout_r2_c1.gif" width="170" height="19"></td>
<td width="76%" background="../../layout/layout_r2_back.gif"><div align="center"><a href="/" class="beige10link"><strong>home</strong></a><span class="dbrown11"> - </span><a href="/buyers" class="beige10link"><strong>available
homes</strong></a><span class="dbrown11"> - </span><a href="/sellers" class="beige10link"><strong>sellers</strong></a><span class="dbrown11"> - </span><a href="/investors" class="beige10link"><strong>investors</strong></a><span class="dbrown11"> - </span><a href="/references" class="beige10link"><strong>references</strong></a><span class="dbrown11"> - </span><a href="/affiliates" class="beige10link"><strong>affiliates</strong></a><span class="dbrown11"> - </span><a href="/links" class="beige10link"><strong>links</strong></a><span class="dbrown11"> - <a href="/contactus" class="beige10link"><strong></strong></a></span><a href="/contactus" class="beige10link"><strong>contact
us</strong></a></div>
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" background="../../layout/formback.gif"> </td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="26%" valign="top" bgcolor="#CDCAB8">
<table width="100%" border="0" cellspacing="4" cellpadding="3">
<tr>
<td height="71" valign="top"><div align="left"><span class="dbrown11"><strong>Content
Administration:</strong></span><span class="dbrown11"> Welcome
to the admin section of cashtruck.com - use the following
links to perform administrative functions.</span></div>
</td>
</tr>
<tr>
<td height="14"><div align="center"><img src="../../layout/brownline.gif" width="90%" height="2"></div>
</td>
</tr>
<tr>
<td height="101">
<p> <span class="dbrown11"><strong>Quick Options:</strong></span><br>
<a href="/login" class="dbrown11link"> > Login</a><br>
<a href="/login/logout.asp" class="dbrown11link">> Logout</a><br>
<a href="/admin" class="dbrown11link">> Site
Administration</a><br>
<a href="javascript:history.go(-1);" class="dbrown11link">> Previous
Page</a><br>
<br>
</p>
</td>
</tr>
<tr>
<td height="8"><div align="center"><img src="../../layout/brownline.gif" width="90%" height="2"></div>
</td>
</tr>
<tr>
<td class="dbrown10">  </td>
</tr>

</table>
</td>
<td width="74%" valign="top"> <table width="100%" height="240" border="0" cellpadding="4" cellspacing="4">
<tr>
<td height="232" valign="top"><div align="center" class="dbrown13">
<p><strong> Enter photo Information<br>
<span class="beige13"><br>
Step 2. Enter photo information</span><br>
<img src="../../layout/beigeline.gif" width="90%" height="1"></strong><br>
<br>
<font color="#FF0000">photos must be named 01, 02, etc. and
end with .jpg (example: 01.jpg)</font></p>
<form ACTION="<%=MM_editAction%>" METHOD="post" enctype="multipart/form-data" name="FormUpload" id="FormUpload" onSubmit="checkFileUpload(this,'JPG',true,'','','','','','','');showProgressWindow('fileCopyProgress.htm',300,100);return document.MM_returnValue">

Select a photo to upload:
<input name="Photo_Name" type="file" id="Photo_Name" onChange="checkOneFileUpload(this,'JPG',true,'','','','','','','')" size="30">
<br>
<input name="ListingID" type="hidden" id="ListingID" value="<%=Session("ListingID"%>">
<br>
<input type="submit" name="submit" value="Upload Now">
<br>
<br>
<a href="javascript:history.go(-1);" class="dbrown11link">Previous Page</a>
<input type="hidden" name="MM_insert" value="FormUpload">
</form>



</p>
</div>
</td>
</tr>
</table></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="2" colspan="2"><img src="../../layout/beigeline.gif" width="100%" height="2"></td>
</tr>
<tr>
<td width="90%" class="darkbrowncontent"><div align="center" class="dbrown10"><strong>Denali
Investment Group, Inc. and Affiliated Investors has been a
member of the Better Business Bureau since October 2000. This
means it supports the Bureau's services to the public and meets
our membership standards.</strong></div>
</td>
<td width="10%"><a href="www.bbb.com/" target="_blank"><img src="../../layout/layout_r7_c5.gif" width="70" height="38" border="0"></a></td>
</tr>
</table>
<table width="100%" height="21" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="2"><img src="../../layout/beigeline.gif" width="100%" height="2"></td>
</tr>
<tr>
<td height="19"><div align="center"><a href="/" class="beige10link">home</a> - <a href="/buyers" class="beige10link">available
homes</a> - <a href="/sellers" class="beige10link">sellers</a> - <a href="/investors" class="beige10link">investors</a> - <a href="/references" class="beige10link">references</a> - <a href="/affiliates" class="beige10link">affiliates</a> - <a href="/links" class="beige10link">links</a> - <a href="/contactus" class="beige10link">contact
us</a> </div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table width="761" border="0" cellspacing="3" cellpadding="3">
<tr>
<td><div align="center"><span class="beige10link">copyright 2003 <a href="www.cashtruck.com" class="beige10link">cashtruck.com</a> |
All rights reserved</span></div>
</td>
</tr>
</table>
</body>
</html>
<%
rsListings.Close()
Set rsListings = Nothing
%>
<%
rsPhotos.Close()
Set rsPhotos = Nothing
%>


Edited by - joshwagner on 20 Mar 2003 19:27:48

Reply to this topic