Orroland
asked on
Can a form timeout - enctype error?
I have a simple form that updates a record and uploads an image file. My client (on a 30kbps dial-up connection) seems to get errors "Form was submitted with no ENCTYPE="multipart/form-da ta"" even though this is specified in the form itself. This happens whether she tries to upload an image or not and intermittantly.
She is using IE6 and Windows XP, I cannot work out what would cause this - apart from the form data 'timing out'.
She is using IE6 and Windows XP, I cannot work out what would cause this - apart from the form data 'timing out'.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
any ideas...?
Take a look at my second post to see if that makes any sense.
The only other thing that I can think of, and this is pure speculation, is that the data being sent from the client to the server is getting garbled and then it throws the error.
FtB
The only other thing that I can think of, and this is pure speculation, is that the data being sent from the client to the server is getting garbled and then it throws the error.
FtB
ASKER
Thanks for the link - this is not the problem.
I suppose that I just have to go there and eliminate 'human error'!
I suppose that I just have to go there and eliminate 'human error'!
May I have the code for that please?
;->
If this is the only person having that problem, and this person is using a modem, there could be a number of factors such as a noisy line, and etc. Again, this is pure speculation.
FtB
;->
If this is the only person having that problem, and this person is using a modem, there could be a number of factors such as a noisy line, and etc. Again, this is pure speculation.
FtB
ASKER
Yes, they are using a modem. Their connection is very poor - and the problem is intermittant. The code for the upload page - the two include files in the next post:
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../Connections/broom tacklebox. asp" -->
<!--#include file="../ScriptLibrary/inc ResizeAddO n.asp" -->
<!--#include file="../ScriptLibrary/inc PureUpload .asp" -->
<%
'*** Pure ASP File Upload -------------------------- ---------- ---------- -------
' Copyright (c) 2001-2002 George Petrov, www.UDzone.com
' Process the upload
' Version: 2.0.9
'------------------------- ---------- ---------- ---------- ---------- ---------- ---
'*** File Upload to: """../uploads""", Extensions: "JPG,JPEG", Form: form1, Redirect: "", "file", "", "uniq", "false", "", "" , "", "", "", "", "600", "", "", ""
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 "<strong>You don't have latest version of ScriptLibrary/incPureUploa d.asp uploaded on the server.</strong><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 = 600
RequestBin = Request.BinaryRead(Request .TotalByte s)
Set UploadRequest = CreateObject("Scripting.Di ctionary")
BuildUploadRequest RequestBin, """../uploads""", "file", "", "uniq"
If (GP_redirectPage <> "" and not (CStr(UploadFormRequest("M M_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_redir ectPage)
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/ResizeIm age.aspx"
RUF_path = "../uploads"
RUF_ResizeImages = true
RUF_maxWidth = "300"
RUF_maxHeight = "300"
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.ServerVariabl es("SCRIPT _NAME"))
If (UploadQueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(UploadQu eryString)
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("M M_update") ) = "form1" And CStr(UploadFormRequest("MM _recordId" )) <> "") Then
MM_editConnection = MM_broomtacklebox_STRING
MM_editTable = "manufacturers"
MM_editColumn = "manufacturerID"
MM_recordId = "" + UploadFormRequest("MM_reco rdId") + ""
MM_editRedirectUrl = "manufacturers_edit_list.a sp"
MM_fieldsStr = "manufacturername|value|ma nufacturer image|valu e|manufact urerdescri ption|valu e|manufact urerhome|v alue"
MM_columnsStr = "manufacturername|',none,' '|manufact urerimage| ',none,''| manufactur erdescript ion|',none ,''|manufa cturerhome |none,'1', '0'"
' create the MM_fields and MM_columns arrays
MM_columnsStr = FixColumnsForUpload(MM_fie ldsStr,MM_ columnsStr )
MM_fieldsStr = FixFieldsForUpload(MM_fiel dsStr,MM_c olumnsStr)
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
%>
<%
' *** Update Record: (Modified for File Upload) construct a sql update statement and execute it
If (CStr(UploadFormRequest("M M_update") ) <> "" And CStr(UploadFormRequest("MM _recordId" )) <> "") Then
' 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") 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_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.ActiveConnectio n = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnectio n.Close
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editR edirectUrl )
End If
End If
End If
%>
<%
Dim manufacturers__MMColParam
manufacturers__MMColParam = "1"
If (Request.QueryString("manu facturerID ") <> "") Then
manufacturers__MMColParam = Request.QueryString("manuf acturerID" )
End If
%>
<%
Dim manufacturers
Dim manufacturers_numRows
Set manufacturers = Server.CreateObject("ADODB .Recordset ")
manufacturers.ActiveConnec tion = MM_broomtacklebox_STRING
manufacturers.Source = "SELECT * FROM manufacturers WHERE manufacturerID = " + Replace(manufacturers__MMC olParam, "'", "''") + ""
manufacturers.CursorType = 0
manufacturers.CursorLocati on = 2
manufacturers.LockType = 1
manufacturers.Open()
manufacturers_numRows = 0
%>
<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers="broomt ackleboxad min"
MM_authFailedURL="login_fa il.asp"
MM_grantAccess=false
If Request.Cookies("MM_Userna me") <> "" Then
If (false Or CStr(Request.Cookies("MM_U serAuthori zation"))= "") Or _
(InStr(1,MM_authorizedUser s,Request. Cookies("M M_UserAuth orization" ))>=1) Then
MM_grantAccess = true
End If
End If
If Not MM_grantAccess Then
MM_qsChar = "?"
If (InStr(1,MM_authFailedURL, "?") >= 1) Then MM_qsChar = "&"
MM_referrer = Request.ServerVariables("U RL")
if (Len(Request.QueryString() ) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referr er)
Response.Redirect(MM_authF ailedURL)
End If
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/admin .dwt.asp" codeOutsideHTMLIsLocked="f alse" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Broom Tackle Box - web site admin centre</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<meta name="author" content="SuperWebs Ltd - www.superwebs.co.uk" />
<script type="text/javascript" language="javascript" src="../Templates/navigati on_admin.j s">
function checkFileUpload(form,exten sions,requ ireUpload, sizeLimit, minWidth,m inHeight,m axWidth,ma xHeight,sa veWidth,sa veHeight) { //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,e xtensions, requireUpl oad,sizeLi mit,minWid th,minHeig ht,maxWidt h,maxHeigh t,saveWidt h,saveHeig ht);
} }
function checkOneFileUpload(field,e xtensions, requireUpl oad,sizeLi mit,minWid th,minHeig ht,maxWidt h,maxHeigh t,saveWidt h,saveHeig ht) { //v2.09
document.MM_returnValue = true;
if (extensions != '') var re = new RegExp("\.(" + extensions.replace(/,/gi," |").replac e(/\s/gi," ") + ")$","i");
if (field.value == '') {
if (requireUpload) {alert('File is required!');document.MM_re turnValue = 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,m axHeight,s aveWidth,s aveHeight) ;
} }
}
function showImageDimensions(fieldI mg) { //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 .saveHeigh t].value = img.height;
document.MM_returnValue = true;
} }
function checkImageDimensions(field ,sizeL,min W,minH,max W,maxH,sav eW,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 ,'/').repl ace(/:/gi, '|').repla ce(/"/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>
<link href="../css/broomtacklebo x.css" rel="stylesheet" type="text/css">
<meta name="robots" content="NOINDEX" />
</head>
<body onLoad="initSwipeMenu()" onUnload="macGo()">
<table width="100%" border="0" bgcolor="#FFFFFF" class="main_table">
<tr>
<td class="arial24">BROOM TACKLE BOX - WEB SITE ADMIN CENTRE</td>
</tr>
<tr>
<td><img src="../images/dot-green.g if" width="100%" height="2"></td>
</tr>
<tr>
<td class="arial24"><img src="../images/shim.gif" width="24" height="24">
<div id="imageHolder" name="SMBxx" style="position:absolute; width:1px; z-index:0; visibility: hidden; left: 0px; top: 0px"> <img src="" width="1" height="1"> <img src="" width="1" height="1"> <img src="" width="1" height="1"> <img src="" width="1" height="1"> </div></td>
</tr>
<tr>
<td valign="top"> <!-- #BeginEditable "main" -->
<table width="100%" border="0">
<tr>
<td valign="top"><p class="arial14"><strong>&g t;><a href="admin_centre.asp">Ad min centre</a> >>Edit manufacturers</strong></p>
<form action="<%=MM_editAction%> " method="POST" enctype="multipart/form-da ta" name="form1">
<table width="100%" align="center">
<tr align="left" valign="baseline" class="arial12">
<td colspan="2" nowrap>Manufacturer name:<br>
<input name="manufacturername" type="text" class="fullwidth" value="<%=(manufacturers.F ields.Item ("manufact urername") .Value)%>" size="32"> </td>
</tr>
<tr align="left" valign="baseline" class="arial12">
<td width="5%" nowrap>Image:</td>
<td width="95%"> <input name="manufacturerimage" type="file" id="manufacturerimage" value="<%=(manufacturers.F ields.Item ("manufact urerimage" ).Value)%> "></td>
</tr>
<tr align="left" valign="baseline" class="arial12">
<td colspan="2" nowrap><input name="manufacturerhome" class="checkbox" type="checkbox" id="manufacturerhome" value="checkbox" <% If (manufacturers.Fields.Item ("manufact urerhome") .Value) = true then Response.Write("checked="" checked""" ) : Response.Write("") %> >
<label for="manufacturerhome">Sho w on home page</label></td>
</tr>
<tr align="left" valign="baseline" class="arial12">
<td colspan="2" nowrap>
<textarea name="manufacturerdescript ion" cols="32"><%=(manufacturer s.Fields.I tem("manuf acturerdes cription") .Value)%>< /textarea>
<script language="JavaScript1.2" defer>
var config = new Object();
config.toolbar = [
// ['fontname'],
// ['fontsize'],
// ['fontstyle'],
// ['linebreak'],
['bold','italic','underlin e','separa tor'],
// ['strikethrough','subscrip t','supers cript','se parator'],
['justifyleft','justifycen ter','just ifyright', 'separator '],
['OrderedList','UnOrderedL ist','Outd ent','Inde nt','separ ator'],
['forecolor','backcolor',' separator' ],
['HorizontalRule','Createl ink'],
// ['about'],
];
config.width = "95%";
config.height = "100px";
config.bodyStyle = 'background-color: white; font-family: "Verdana"; font-size: 12px;';
editor_generate('manufactu rerdescrip tion',conf ig);
</script> </td>
</tr>
<tr align="left" valign="baseline" class="arial12">
<td colspan="2" nowrap>
<input type="submit" value="Save">
<input type="button" name="Button" value="Delete" onClick="go_URL('manufactu rers_delet e.asp?manu facturerID =<%= manufacturers.Fields.Item( "manufactu rerID").Va lue %>')">
</td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="MM_recordId" value="<%= manufacturers.Fields.Item( "manufactu rerID").Va lue %>">
</form>
<p> </p></td>
</tr>
</table>
<!-- #EndEditable --></td>
</tr>
<tr>
<td height="2"><img src="../images/dot-green.g if" width="100%" height="2"></td>
</tr>
<tr>
<td align="center" class="arial12">
<p>© Broom Tackle Box <%=year(date)%>. All Rights Reserved.</p>
<p>Designed by <a href="http://www.superwebs.co.uk" target="_blank">SuperWebs< /a></p></t d>
</tr>
</table>
</body>
<!-- InstanceEnd --></html>
<%
manufacturers.Close()
Set manufacturers = Nothing
%>
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../Connections/broom
<!--#include file="../ScriptLibrary/inc
<!--#include file="../ScriptLibrary/inc
<%
'*** Pure ASP File Upload --------------------------
' Copyright (c) 2001-2002 George Petrov, www.UDzone.com
' Process the upload
' Version: 2.0.9
'-------------------------
'*** File Upload to: """../uploads""", Extensions: "JPG,JPEG", Form: form1, Redirect: "", "file", "", "uniq", "false", "", "" , "", "", "", "", "600", "", "", ""
Dim GP_redirectPage, RequestBin, UploadQueryString, GP_uploadAction, UploadRequest
PureUploadSetup
If (CStr(Request.QueryString(
on error resume next
Dim reqPureUploadVersion, foundPureUploadVersion
reqPureUploadVersion = 2.09
foundPureUploadVersion = getPureUploadVersion()
if err or reqPureUploadVersion > foundPureUploadVersion then
Response.Write "<strong>You don't have latest version of ScriptLibrary/incPureUploa
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 = 600
RequestBin = Request.BinaryRead(Request
Set UploadRequest = CreateObject("Scripting.Di
BuildUploadRequest RequestBin, """../uploads""", "file", "", "uniq"
If (GP_redirectPage <> "" and not (CStr(UploadFormRequest("M
If (InStr(1, GP_redirectPage, "?", vbTextCompare) = 0 And UploadQueryString <> "") Then
GP_redirectPage = GP_redirectPage & "?" & UploadQueryString
End If
Response.Redirect(GP_redir
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(
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/ResizeIm
RUF_path = "../uploads"
RUF_ResizeImages = true
RUF_maxWidth = "300"
RUF_maxHeight = "300"
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.ServerVariabl
If (UploadQueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(UploadQu
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("M
MM_editConnection = MM_broomtacklebox_STRING
MM_editTable = "manufacturers"
MM_editColumn = "manufacturerID"
MM_recordId = "" + UploadFormRequest("MM_reco
MM_editRedirectUrl = "manufacturers_edit_list.a
MM_fieldsStr = "manufacturername|value|ma
MM_columnsStr = "manufacturername|',none,'
' create the MM_fields and MM_columns arrays
MM_columnsStr = FixColumnsForUpload(MM_fie
MM_fieldsStr = FixFieldsForUpload(MM_fiel
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_
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
%>
<%
' *** Update Record: (Modified for File Upload) construct a sql update statement and execute it
If (CStr(UploadFormRequest("M
' 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") 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_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
MM_editCmd.ActiveConnectio
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnectio
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editR
End If
End If
End If
%>
<%
Dim manufacturers__MMColParam
manufacturers__MMColParam = "1"
If (Request.QueryString("manu
manufacturers__MMColParam = Request.QueryString("manuf
End If
%>
<%
Dim manufacturers
Dim manufacturers_numRows
Set manufacturers = Server.CreateObject("ADODB
manufacturers.ActiveConnec
manufacturers.Source = "SELECT * FROM manufacturers WHERE manufacturerID = " + Replace(manufacturers__MMC
manufacturers.CursorType = 0
manufacturers.CursorLocati
manufacturers.LockType = 1
manufacturers.Open()
manufacturers_numRows = 0
%>
<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers="broomt
MM_authFailedURL="login_fa
MM_grantAccess=false
If Request.Cookies("MM_Userna
If (false Or CStr(Request.Cookies("MM_U
(InStr(1,MM_authorizedUser
MM_grantAccess = true
End If
End If
If Not MM_grantAccess Then
MM_qsChar = "?"
If (InStr(1,MM_authFailedURL,
MM_referrer = Request.ServerVariables("U
if (Len(Request.QueryString()
MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referr
Response.Redirect(MM_authF
End If
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/admin
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Broom Tackle Box - web site admin centre</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<meta name="author" content="SuperWebs Ltd - www.superwebs.co.uk" />
<script type="text/javascript" language="javascript" src="../Templates/navigati
function checkFileUpload(form,exten
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,e
} }
function checkOneFileUpload(field,e
document.MM_returnValue = true;
if (extensions != '') var re = new RegExp("\.(" + extensions.replace(/,/gi,"
if (field.value == '') {
if (requireUpload) {alert('File is required!');document.MM_re
} 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|
if(re.test(field.value) && (sizeLimit != '' || minWidth != '' || minHeight != '' || maxWidth != '' || maxHeight != '' || saveWidth != '' || saveHeight != '')) {
checkImageDimensions(field
} }
}
function showImageDimensions(fieldI
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
if (img.saveHeight != '') document.PU_uploadForm[img
document.MM_returnValue = true;
} }
function checkImageDimensions(field
if (!document.layers) {
var isNS6 = (!document.all && document.getElementById ? true : false);
document.MM_returnValue = false; var imgURL = 'file:///' + field.value.replace(/\\/gi
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.
}
</script>
<link href="../css/broomtacklebo
<meta name="robots" content="NOINDEX" />
</head>
<body onLoad="initSwipeMenu()" onUnload="macGo()">
<table width="100%" border="0" bgcolor="#FFFFFF" class="main_table">
<tr>
<td class="arial24">BROOM TACKLE BOX - WEB SITE ADMIN CENTRE</td>
</tr>
<tr>
<td><img src="../images/dot-green.g
</tr>
<tr>
<td class="arial24"><img src="../images/shim.gif" width="24" height="24">
<div id="imageHolder" name="SMBxx" style="position:absolute; width:1px; z-index:0; visibility: hidden; left: 0px; top: 0px"> <img src="" width="1" height="1"> <img src="" width="1" height="1"> <img src="" width="1" height="1"> <img src="" width="1" height="1"> </div></td>
</tr>
<tr>
<td valign="top"> <!-- #BeginEditable "main" -->
<table width="100%" border="0">
<tr>
<td valign="top"><p class="arial14"><strong>&g
<form action="<%=MM_editAction%>
<table width="100%" align="center">
<tr align="left" valign="baseline" class="arial12">
<td colspan="2" nowrap>Manufacturer name:<br>
<input name="manufacturername" type="text" class="fullwidth" value="<%=(manufacturers.F
</tr>
<tr align="left" valign="baseline" class="arial12">
<td width="5%" nowrap>Image:</td>
<td width="95%"> <input name="manufacturerimage" type="file" id="manufacturerimage" value="<%=(manufacturers.F
</tr>
<tr align="left" valign="baseline" class="arial12">
<td colspan="2" nowrap><input name="manufacturerhome" class="checkbox" type="checkbox" id="manufacturerhome" value="checkbox" <% If (manufacturers.Fields.Item
<label for="manufacturerhome">Sho
</tr>
<tr align="left" valign="baseline" class="arial12">
<td colspan="2" nowrap>
<textarea name="manufacturerdescript
<script language="JavaScript1.2" defer>
var config = new Object();
config.toolbar = [
// ['fontname'],
// ['fontsize'],
// ['fontstyle'],
// ['linebreak'],
['bold','italic','underlin
// ['strikethrough','subscrip
['justifyleft','justifycen
['OrderedList','UnOrderedL
['forecolor','backcolor','
['HorizontalRule','Createl
// ['about'],
];
config.width = "95%";
config.height = "100px";
config.bodyStyle = 'background-color: white; font-family: "Verdana"; font-size: 12px;';
editor_generate('manufactu
</script> </td>
</tr>
<tr align="left" valign="baseline" class="arial12">
<td colspan="2" nowrap>
<input type="submit" value="Save">
<input type="button" name="Button" value="Delete" onClick="go_URL('manufactu
</td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="MM_recordId" value="<%= manufacturers.Fields.Item(
</form>
<p> </p></td>
</tr>
</table>
<!-- #EndEditable --></td>
</tr>
<tr>
<td height="2"><img src="../images/dot-green.g
</tr>
<tr>
<td align="center" class="arial12">
<p>© Broom Tackle Box <%=year(date)%>. All Rights Reserved.</p>
<p>Designed by <a href="http://www.superwebs.co.uk" target="_blank">SuperWebs<
</tr>
</table>
</body>
<!-- InstanceEnd --></html>
<%
manufacturers.Close()
Set manufacturers = Nothing
%>
ASKER
incPureUpload.asp:
<SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
'*** Pure ASP File Upload -------------------------- ---------- ---------- -------
' Copyright 2001-2002 (c) George Petrov, www.UDzone.com
'
' Script partially based on code from Philippe Collignon
' (http://www.asptoday.com/articles/20000316.htm)
'
' New features added:
' * Fast file save with ADO 2.5 stream object
' * new file handling, wrapper functions, extra error checking
' * UltraDev Server Behavior extension
' * Progress bars, file limit checking, file type checking, file existence checking
' * Support for UltraDev Insert/Update Server Behavior
' * and much more ...
'
' Version: 2.0.9
'------------------------- ---------- ---------- ---------- ---------- ---------- ---
Function getPureUploadVersion()
getPureUploadVersion = 2.09
End Function
Sub BuildUploadRequest(Request Bin,Upload Directory, storeType, sizeLimit, nameConfli ct)
Dim PosBeg, PosEnd, checkADOConn, AdoVersion, Length, boundary, boundaryPos, Pos
Dim PosFile, Name, PosBound, FileName, ContentType, Value, ValueBeg, ValueEnd, ValueLen
'Get the boundary
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,g etByteStri ng(chr(13) ))
if PosEnd = 0 then
Response.Write "<strong>Form was submitted with no ENCTYPE=""multipart/form-d ata""</str ong><br>"
Response.Write "Please correct and <A HREF=""javascript:history. back(1)""> try again</a>"
Response.End
end if
'Check ADO Version
set checkADOConn = Server.CreateObject("ADODB .Connectio n")
on error resume next
adoVersion = CSng(checkADOConn.Version)
if err then
adoVersion = Replace(checkADOConn.Versi on,".","," )
adoVersion = CSng(adoVersion)
end if
err.clear
on error goto 0
set checkADOConn = Nothing
if adoVersion < 2.5 then
Response.Write "<strong>You don't have ADO 2.5 installed on the server.</strong><br>"
Response.Write "The File Upload extension needs ADO 2.5 or greater to run properly.<br>"
Response.Write "You can download the latest MDAC (ADO is included) from <a href=""www.microsoft.com/data"">www.microsoft.com/data</a><br>"
Response.End
end if
'Check content length if needed
Length = CLng(Request.ServerVariabl es("HTTP_C ontent_Len gth")) 'Get Content-Length header
If "" & sizeLimit <> "" Then
sizeLimit = CLng(sizeLimit) * 1024
If Length > sizeLimit Then
Request.BinaryRead (Length)
Response.Write "Upload size " & FormatNumber(Length, 0) & "B exceeds limit of " & FormatNumber(sizeLimit, 0) & "B"
Response.Write "Please correct and <A HREF=""javascript:history. back(1)""> try again</a>"
Response.End
End If
End If
boundary = MidB(RequestBin,PosBeg,Pos End-PosBeg )
boundaryPos = InstrB(1,RequestBin,bounda ry)
'Get all data inside the boundaries
Do until (boundaryPos=InstrB(Reques tBin,bound ary & getByteString("--")))
'Members variable of objects are put in a dictionary object
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Di ctionary")
'Get an object name
Pos = InstrB(BoundaryPos,Request Bin,getByt eString("C ontent-Dis position") )
Pos = InstrB(Pos,RequestBin,getB yteString( "name="))
PosBeg = Pos+6
PosEnd = InstrB(PosBeg,RequestBin,g etByteStri ng(chr(34) ))
Name = LCase(getString(MidB(Reque stBin,PosB eg,PosEnd- PosBeg)))
PosFile = InstrB(BoundaryPos,Request Bin,getByt eString("f ilename=") )
PosBound = InstrB(PosEnd,RequestBin,b oundary)
'Test if object is of file type
If PosFile<>0 AND (PosFile<PosBound) Then
'Get Filename, content-type and content of file
PosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,RequestBin,g etByteStri ng(chr(34) ))
FileName = getString(MidB(RequestBin, PosBeg,Pos End-PosBeg ))
FileName = RemoveInvalidChars(Mid(Fil eName,InSt rRev(FileN ame,"\")+1 ))
'Add filename to dictionary object
UploadControl.Add "FileName", FileName
Pos = InstrB(PosEnd,RequestBin,g etByteStri ng("Conten t-Type:"))
PosBeg = Pos+14
PosEnd = InstrB(PosBeg,RequestBin,g etByteStri ng(chr(13) ))
'Add content-type to dictionary object
ContentType = getString(MidB(RequestBin, PosBeg,Pos End-PosBeg ))
UploadControl.Add "ContentType",ContentType
'Get content of object
PosBeg = PosEnd+4
PosEnd = InstrB(PosBeg,RequestBin,b oundary)-2
Value = FileName
ValueBeg = PosBeg-1
ValueLen = PosEnd-Posbeg
Else
'Get content of object
Pos = InstrB(Pos,RequestBin,getB yteString( chr(13)))
PosBeg = Pos+4
PosEnd = InstrB(PosBeg,RequestBin,b oundary)-2
Value = getString(MidB(RequestBin, PosBeg,Pos End-PosBeg ))
ValueBeg = 0
ValueEnd = 0
End If
'Add content to dictionary object
UploadControl.Add "Value" , Value
UploadControl.Add "ValueBeg" , ValueBeg
UploadControl.Add "ValueLen" , ValueLen
'Add dictionary object to main dictionary
if UploadRequest.Exists(name) then
UploadRequest(name).Item(" Value") = UploadRequest(name).Item(" Value") & "," & Value
else
UploadRequest.Add name, UploadControl
end if
'Loop to next object
BoundaryPos=InstrB(Boundar yPos+LenB( boundary), RequestBin ,boundary)
Loop
Dim GP_keys, GP_i, GP_curKey, GP_value, GP_valueBeg, GP_valueLen, GP_curPath, GP_FullPath
Dim GP_CurFileName, GP_FullFileName, fso, GP_BegFolder, GP_RelFolder, GP_FileExist, Begin_Name_Num
Dim orgUploadDirectory
if InStr(UploadDirectory,"""" ) > 0 then
on error resume next
orgUploadDirectory = UploadDirectory
UploadDirectory = eval(UploadDirectory)
if err then
Response.Write "<B>Upload folder is invalid</B><br><br>"
Response.Write "Upload Folder: " & Trim(orgUploadDirectory) & "<br>"
Response.Write "Please correct and <A HREF=""javascript:history. back(1)""> try again</a>"
err.clear
response.End
end if
on error goto 0
end if
GP_keys = UploadRequest.Keys
for GP_i = 0 to UploadRequest.Count - 1
GP_curKey = GP_keys(GP_i)
'Save all uploaded files
if UploadRequest.Item(GP_curK ey).Item(" FileName") <> "" then
GP_value = UploadRequest.Item(GP_curK ey).Item(" Value")
GP_valueBeg = UploadRequest.Item(GP_curK ey).Item(" ValueBeg")
GP_valueLen = UploadRequest.Item(GP_curK ey).Item(" ValueLen")
'Get the path
if InStr(UploadDirectory,"\") > 0 then
GP_curPath = UploadDirectory
if Mid(GP_curPath,Len(GP_curP ath),1) <> "\" then
GP_curPath = GP_curPath & "\"
end if
GP_FullPath = GP_curPath
else
GP_curPath = Request.ServerVariables("P ATH_INFO")
GP_curPath = Trim(Mid(GP_curPath,1,InSt rRev(GP_cu rPath,"/") ) & UploadDirectory)
if Mid(GP_curPath,Len(GP_curP ath),1) <> "/" then
GP_curPath = GP_curPath & "/"
end if
GP_FullPath = Trim(Server.mappath(GP_cur Path))
end if
if GP_valueLen = 0 then
Response.Write "<B>An error has occured saving uploaded file!</B><br><br>"
Response.Write "Filename: " & Trim(GP_curPath) & UploadRequest.Item(GP_curK ey).Item(" FileName") & "<br>"
Response.Write "File does not exists or is empty.<br>"
Response.Write "Please correct and <A HREF=""javascript:history. back(1)""> try again</a>"
response.End
end if
'Create a Stream instance
Dim GP_strm1, GP_strm2
Set GP_strm1 = Server.CreateObject("ADODB .Stream")
Set GP_strm2 = Server.CreateObject("ADODB .Stream")
'Open the stream
GP_strm1.Open
GP_strm1.Type = 1 'Binary
GP_strm2.Open
GP_strm2.Type = 1 'Binary
GP_strm1.Write RequestBin
GP_strm1.Position = GP_ValueBeg
GP_strm1.CopyTo GP_strm2,GP_ValueLen
'Create and Write to a File
GP_CurFileName = UploadRequest.Item(GP_curK ey).Item(" FileName")
GP_FullFileName = GP_FullPath & "\" & GP_CurFileName
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
'Check if the folder exist
If NOT fso.FolderExists(GP_FullPa th) Then
GP_BegFolder = InStr(GP_FullPath,"\")
while GP_begFolder > 0
GP_RelFolder = Mid(GP_FullPath,1,GP_BegFo lder-1)
If NOT fso.FolderExists(GP_RelFol der) Then
fso.CreateFolder(GP_RelFol der)
end if
GP_BegFolder = InStr(GP_BegFolder+1,GP_Fu llPath,"\" )
wend
If NOT fso.FolderExists(GP_FullPa th) Then
fso.CreateFolder(GP_FullPa th)
end if
end if
'Check if the file already exist
GP_FileExist = false
If fso.FileExists(GP_FullFile Name) Then
GP_FileExist = true
End If
if nameConflict = "error" and GP_FileExist then
Response.Write "<B>File already exists!</B><br><br>"
Response.Write "Please correct and <A HREF=""javascript:history. back(1)""> try again</a>"
GP_strm1.Close
GP_strm2.Close
response.End
end if
if ((nameConflict = "over" or nameConflict = "uniq") and GP_FileExist) or (NOT GP_FileExist) then
if nameConflict = "uniq" and GP_FileExist then
Begin_Name_Num = 0
while GP_FileExist
Begin_Name_Num = Begin_Name_Num + 1
GP_FullFileName = Trim(GP_FullPath)& "\" & fso.GetBaseName(GP_CurFile Name) & "_" & Begin_Name_Num & "." & fso.GetExtensionName(GP_Cu rFileName)
GP_FileExist = fso.FileExists(GP_FullFile Name)
wend
UploadRequest.Item(GP_curK ey).Item(" FileName") = fso.GetBaseName(GP_CurFile Name) & "_" & Begin_Name_Num & "." & fso.GetExtensionName(GP_Cu rFileName)
UploadRequest.Item(GP_curK ey).Item(" Value") = UploadRequest.Item(GP_curK ey).Item(" FileName")
end if
on error resume next
GP_strm2.SaveToFile GP_FullFileName,2
if err then
Response.Write "<B>An error has occured saving uploaded file!</B><br><br>"
Response.Write "Filename: " & Trim(GP_curPath) & UploadRequest.Item(GP_curK ey).Item(" FileName") & "<br>"
Response.Write "Maybe the destination directory does not exist, or you don't have write permission.<br>"
Response.Write "Please correct and <A HREF=""javascript:history. back(1)""> try again</a>"
err.clear
GP_strm1.Close
GP_strm2.Close
response.End
end if
GP_strm1.Close
GP_strm2.Close
if storeType = "path" then
UploadRequest.Item(GP_curK ey).Item(" Value") = GP_curPath & UploadRequest.Item(GP_curK ey).Item(" Value")
end if
on error goto 0
end if
end if
next
End Sub
'String to byte string conversion
Function getByteString(StringStr)
Dim i, char
For i = 1 to Len(StringStr)
char = Mid(StringStr,i,1)
getByteString = getByteString & chrB(AscB(char))
Next
End Function
'Byte string to string conversion (with double-byte support now)
Function getString(StringBin)
Dim intCount,get1Byte
getString =""
For intCount = 1 to LenB(StringBin)
get1Byte = MidB(StringBin,intCount,1)
getString = getString & chr(AscB(get1Byte))
Next
End Function
Function UploadFormRequest(name)
Dim keyName
keyName = LCase(name)
if IsObject(UploadRequest) then
if UploadRequest.Exists(keyNa me) then
if UploadRequest.Item(keyName ).Exists(" Value") then
UploadFormRequest = UploadRequest.Item(keyName ).Item("Va lue")
end if
end if
end if
End Function
Function RemoveInvalidChars(str)
Dim newStr, ci, curChar
for ci = 1 to Len(str)
curChar = Asc(LCase(Mid(str,ci,1)))
if curChar = 95 or curChar = 45 or curChar = 46 or (curChar >= 97 and curChar <= 122) or (curChar >= 48 and curChar <= 57) then
newStr = newStr & Mid(str,ci,1)
end if
next
RemoveInvalidChars = newStr
End Function
Sub PureUploadSetup()
UploadQueryString = Replace(Request.QueryStrin g,"GP_uplo ad=true"," ")
if mid(UploadQueryString,1,1) = "&" then
UploadQueryString = Mid(UploadQueryString,2)
end if
GP_uploadAction = CStr(Request.ServerVariabl es("URL")) & "?GP_upload=true"
If (Request.QueryString <> "") Then
if UploadQueryString <> "" then
GP_uploadAction = GP_uploadAction & "&" & UploadQueryString
end if
End If
End Sub
Function FixFieldsForUpload(GP_fiel dsStr, GP_columnsStr)
Dim GP_counter, GP_Fields, GP_Columns, GP_FieldName, GP_FieldValue, GP_CurFileName, GP_CurContentType
GP_Fields = Split(GP_fieldsStr, "|")
GP_Columns = Split(GP_columnsStr, "|")
GP_fieldsStr = ""
' Get the form values
For GP_counter = LBound(GP_Fields) To UBound(GP_Fields) Step 2
GP_FieldName = LCase(GP_Fields(GP_counter ))
GP_FieldValue = GP_Fields(GP_counter+1)
if UploadRequest.Exists(GP_Fi eldName) then
GP_CurFileName = UploadRequest.Item(GP_Fiel dName).Ite m("FileNam e")
GP_CurContentType = UploadRequest.Item(GP_Fiel dName).Ite m("Content Type")
else
GP_CurFileName = ""
GP_CurContentType = ""
end if
if (GP_CurFileName = "" and GP_CurContentType = "") or (GP_CurFileName <> "" and GP_CurContentType <> "") then
GP_fieldsStr = GP_fieldsStr & GP_FieldName & "|" & GP_FieldValue & "|"
end if
Next
if GP_fieldsStr <> "" then
GP_fieldsStr = Mid(GP_fieldsStr,1,Len(GP_ fieldsStr) -1)
else
Response.Write "<B>An error has occured during record update!</B><br><br>"
Response.Write "There are no fields to update ...<br>"
Response.Write "If the file upload field is the only field on your form, you should make it required.<br>"
Response.Write "Please correct and <A HREF=""javascript:history. back(1)""> try again</a>"
Response.End
end if
FixFieldsForUpload = GP_fieldsStr
End Function
Function FixColumnsForUpload(GP_fie ldsStr, GP_columnsStr)
Dim GP_counter, GP_Fields, GP_Columns, GP_FieldName, GP_ColumnName, GP_ColumnValue,GP_CurFileN ame, GP_CurContentType
GP_Fields = Split(GP_fieldsStr, "|")
GP_Columns = Split(GP_columnsStr, "|")
GP_columnsStr = ""
' Get the form values
For GP_counter = LBound(GP_Fields) To UBound(GP_Fields) Step 2
GP_FieldName = LCase(GP_Fields(GP_counter ))
GP_ColumnName = GP_Columns(GP_counter)
GP_ColumnValue = GP_Columns(GP_counter+1)
if UploadRequest.Exists(GP_Fi eldName) then
GP_CurFileName = UploadRequest.Item(GP_Fiel dName).Ite m("FileNam e")
GP_CurContentType = UploadRequest.Item(GP_Fiel dName).Ite m("Content Type")
else
GP_CurFileName = ""
GP_CurContentType = ""
end if
if (GP_CurFileName = "" and GP_CurContentType = "") or (GP_CurFileName <> "" and GP_CurContentType <> "") then
GP_columnsStr = GP_columnsStr & GP_ColumnName & "|" & GP_ColumnValue & "|"
end if
Next
if GP_columnsStr <> "" then
GP_columnsStr = Mid(GP_columnsStr,1,Len(GP _columnsSt r)-1)
end if
FixColumnsForUpload = GP_columnsStr
End Function
</SCRIPT>
<SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
'*** Pure ASP File Upload --------------------------
' Copyright 2001-2002 (c) George Petrov, www.UDzone.com
'
' Script partially based on code from Philippe Collignon
' (http://www.asptoday.com/articles/20000316.htm)
'
' New features added:
' * Fast file save with ADO 2.5 stream object
' * new file handling, wrapper functions, extra error checking
' * UltraDev Server Behavior extension
' * Progress bars, file limit checking, file type checking, file existence checking
' * Support for UltraDev Insert/Update Server Behavior
' * and much more ...
'
' Version: 2.0.9
'-------------------------
Function getPureUploadVersion()
getPureUploadVersion = 2.09
End Function
Sub BuildUploadRequest(Request
Dim PosBeg, PosEnd, checkADOConn, AdoVersion, Length, boundary, boundaryPos, Pos
Dim PosFile, Name, PosBound, FileName, ContentType, Value, ValueBeg, ValueEnd, ValueLen
'Get the boundary
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,g
if PosEnd = 0 then
Response.Write "<strong>Form was submitted with no ENCTYPE=""multipart/form-d
Response.Write "Please correct and <A HREF=""javascript:history.
Response.End
end if
'Check ADO Version
set checkADOConn = Server.CreateObject("ADODB
on error resume next
adoVersion = CSng(checkADOConn.Version)
if err then
adoVersion = Replace(checkADOConn.Versi
adoVersion = CSng(adoVersion)
end if
err.clear
on error goto 0
set checkADOConn = Nothing
if adoVersion < 2.5 then
Response.Write "<strong>You don't have ADO 2.5 installed on the server.</strong><br>"
Response.Write "The File Upload extension needs ADO 2.5 or greater to run properly.<br>"
Response.Write "You can download the latest MDAC (ADO is included) from <a href=""www.microsoft.com/data"">www.microsoft.com/data</a><br>"
Response.End
end if
'Check content length if needed
Length = CLng(Request.ServerVariabl
If "" & sizeLimit <> "" Then
sizeLimit = CLng(sizeLimit) * 1024
If Length > sizeLimit Then
Request.BinaryRead (Length)
Response.Write "Upload size " & FormatNumber(Length, 0) & "B exceeds limit of " & FormatNumber(sizeLimit, 0) & "B"
Response.Write "Please correct and <A HREF=""javascript:history.
Response.End
End If
End If
boundary = MidB(RequestBin,PosBeg,Pos
boundaryPos = InstrB(1,RequestBin,bounda
'Get all data inside the boundaries
Do until (boundaryPos=InstrB(Reques
'Members variable of objects are put in a dictionary object
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Di
'Get an object name
Pos = InstrB(BoundaryPos,Request
Pos = InstrB(Pos,RequestBin,getB
PosBeg = Pos+6
PosEnd = InstrB(PosBeg,RequestBin,g
Name = LCase(getString(MidB(Reque
PosFile = InstrB(BoundaryPos,Request
PosBound = InstrB(PosEnd,RequestBin,b
'Test if object is of file type
If PosFile<>0 AND (PosFile<PosBound) Then
'Get Filename, content-type and content of file
PosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,RequestBin,g
FileName = getString(MidB(RequestBin,
FileName = RemoveInvalidChars(Mid(Fil
'Add filename to dictionary object
UploadControl.Add "FileName", FileName
Pos = InstrB(PosEnd,RequestBin,g
PosBeg = Pos+14
PosEnd = InstrB(PosBeg,RequestBin,g
'Add content-type to dictionary object
ContentType = getString(MidB(RequestBin,
UploadControl.Add "ContentType",ContentType
'Get content of object
PosBeg = PosEnd+4
PosEnd = InstrB(PosBeg,RequestBin,b
Value = FileName
ValueBeg = PosBeg-1
ValueLen = PosEnd-Posbeg
Else
'Get content of object
Pos = InstrB(Pos,RequestBin,getB
PosBeg = Pos+4
PosEnd = InstrB(PosBeg,RequestBin,b
Value = getString(MidB(RequestBin,
ValueBeg = 0
ValueEnd = 0
End If
'Add content to dictionary object
UploadControl.Add "Value" , Value
UploadControl.Add "ValueBeg" , ValueBeg
UploadControl.Add "ValueLen" , ValueLen
'Add dictionary object to main dictionary
if UploadRequest.Exists(name)
UploadRequest(name).Item("
else
UploadRequest.Add name, UploadControl
end if
'Loop to next object
BoundaryPos=InstrB(Boundar
Loop
Dim GP_keys, GP_i, GP_curKey, GP_value, GP_valueBeg, GP_valueLen, GP_curPath, GP_FullPath
Dim GP_CurFileName, GP_FullFileName, fso, GP_BegFolder, GP_RelFolder, GP_FileExist, Begin_Name_Num
Dim orgUploadDirectory
if InStr(UploadDirectory,""""
on error resume next
orgUploadDirectory = UploadDirectory
UploadDirectory = eval(UploadDirectory)
if err then
Response.Write "<B>Upload folder is invalid</B><br><br>"
Response.Write "Upload Folder: " & Trim(orgUploadDirectory) & "<br>"
Response.Write "Please correct and <A HREF=""javascript:history.
err.clear
response.End
end if
on error goto 0
end if
GP_keys = UploadRequest.Keys
for GP_i = 0 to UploadRequest.Count - 1
GP_curKey = GP_keys(GP_i)
'Save all uploaded files
if UploadRequest.Item(GP_curK
GP_value = UploadRequest.Item(GP_curK
GP_valueBeg = UploadRequest.Item(GP_curK
GP_valueLen = UploadRequest.Item(GP_curK
'Get the path
if InStr(UploadDirectory,"\")
GP_curPath = UploadDirectory
if Mid(GP_curPath,Len(GP_curP
GP_curPath = GP_curPath & "\"
end if
GP_FullPath = GP_curPath
else
GP_curPath = Request.ServerVariables("P
GP_curPath = Trim(Mid(GP_curPath,1,InSt
if Mid(GP_curPath,Len(GP_curP
GP_curPath = GP_curPath & "/"
end if
GP_FullPath = Trim(Server.mappath(GP_cur
end if
if GP_valueLen = 0 then
Response.Write "<B>An error has occured saving uploaded file!</B><br><br>"
Response.Write "Filename: " & Trim(GP_curPath) & UploadRequest.Item(GP_curK
Response.Write "File does not exists or is empty.<br>"
Response.Write "Please correct and <A HREF=""javascript:history.
response.End
end if
'Create a Stream instance
Dim GP_strm1, GP_strm2
Set GP_strm1 = Server.CreateObject("ADODB
Set GP_strm2 = Server.CreateObject("ADODB
'Open the stream
GP_strm1.Open
GP_strm1.Type = 1 'Binary
GP_strm2.Open
GP_strm2.Type = 1 'Binary
GP_strm1.Write RequestBin
GP_strm1.Position = GP_ValueBeg
GP_strm1.CopyTo GP_strm2,GP_ValueLen
'Create and Write to a File
GP_CurFileName = UploadRequest.Item(GP_curK
GP_FullFileName = GP_FullPath & "\" & GP_CurFileName
Set fso = CreateObject("Scripting.Fi
'Check if the folder exist
If NOT fso.FolderExists(GP_FullPa
GP_BegFolder = InStr(GP_FullPath,"\")
while GP_begFolder > 0
GP_RelFolder = Mid(GP_FullPath,1,GP_BegFo
If NOT fso.FolderExists(GP_RelFol
fso.CreateFolder(GP_RelFol
end if
GP_BegFolder = InStr(GP_BegFolder+1,GP_Fu
wend
If NOT fso.FolderExists(GP_FullPa
fso.CreateFolder(GP_FullPa
end if
end if
'Check if the file already exist
GP_FileExist = false
If fso.FileExists(GP_FullFile
GP_FileExist = true
End If
if nameConflict = "error" and GP_FileExist then
Response.Write "<B>File already exists!</B><br><br>"
Response.Write "Please correct and <A HREF=""javascript:history.
GP_strm1.Close
GP_strm2.Close
response.End
end if
if ((nameConflict = "over" or nameConflict = "uniq") and GP_FileExist) or (NOT GP_FileExist) then
if nameConflict = "uniq" and GP_FileExist then
Begin_Name_Num = 0
while GP_FileExist
Begin_Name_Num = Begin_Name_Num + 1
GP_FullFileName = Trim(GP_FullPath)& "\" & fso.GetBaseName(GP_CurFile
GP_FileExist = fso.FileExists(GP_FullFile
wend
UploadRequest.Item(GP_curK
UploadRequest.Item(GP_curK
end if
on error resume next
GP_strm2.SaveToFile GP_FullFileName,2
if err then
Response.Write "<B>An error has occured saving uploaded file!</B><br><br>"
Response.Write "Filename: " & Trim(GP_curPath) & UploadRequest.Item(GP_curK
Response.Write "Maybe the destination directory does not exist, or you don't have write permission.<br>"
Response.Write "Please correct and <A HREF=""javascript:history.
err.clear
GP_strm1.Close
GP_strm2.Close
response.End
end if
GP_strm1.Close
GP_strm2.Close
if storeType = "path" then
UploadRequest.Item(GP_curK
end if
on error goto 0
end if
end if
next
End Sub
'String to byte string conversion
Function getByteString(StringStr)
Dim i, char
For i = 1 to Len(StringStr)
char = Mid(StringStr,i,1)
getByteString = getByteString & chrB(AscB(char))
Next
End Function
'Byte string to string conversion (with double-byte support now)
Function getString(StringBin)
Dim intCount,get1Byte
getString =""
For intCount = 1 to LenB(StringBin)
get1Byte = MidB(StringBin,intCount,1)
getString = getString & chr(AscB(get1Byte))
Next
End Function
Function UploadFormRequest(name)
Dim keyName
keyName = LCase(name)
if IsObject(UploadRequest) then
if UploadRequest.Exists(keyNa
if UploadRequest.Item(keyName
UploadFormRequest = UploadRequest.Item(keyName
end if
end if
end if
End Function
Function RemoveInvalidChars(str)
Dim newStr, ci, curChar
for ci = 1 to Len(str)
curChar = Asc(LCase(Mid(str,ci,1)))
if curChar = 95 or curChar = 45 or curChar = 46 or (curChar >= 97 and curChar <= 122) or (curChar >= 48 and curChar <= 57) then
newStr = newStr & Mid(str,ci,1)
end if
next
RemoveInvalidChars = newStr
End Function
Sub PureUploadSetup()
UploadQueryString = Replace(Request.QueryStrin
if mid(UploadQueryString,1,1)
UploadQueryString = Mid(UploadQueryString,2)
end if
GP_uploadAction = CStr(Request.ServerVariabl
If (Request.QueryString <> "") Then
if UploadQueryString <> "" then
GP_uploadAction = GP_uploadAction & "&" & UploadQueryString
end if
End If
End Sub
Function FixFieldsForUpload(GP_fiel
Dim GP_counter, GP_Fields, GP_Columns, GP_FieldName, GP_FieldValue, GP_CurFileName, GP_CurContentType
GP_Fields = Split(GP_fieldsStr, "|")
GP_Columns = Split(GP_columnsStr, "|")
GP_fieldsStr = ""
' Get the form values
For GP_counter = LBound(GP_Fields) To UBound(GP_Fields) Step 2
GP_FieldName = LCase(GP_Fields(GP_counter
GP_FieldValue = GP_Fields(GP_counter+1)
if UploadRequest.Exists(GP_Fi
GP_CurFileName = UploadRequest.Item(GP_Fiel
GP_CurContentType = UploadRequest.Item(GP_Fiel
else
GP_CurFileName = ""
GP_CurContentType = ""
end if
if (GP_CurFileName = "" and GP_CurContentType = "") or (GP_CurFileName <> "" and GP_CurContentType <> "") then
GP_fieldsStr = GP_fieldsStr & GP_FieldName & "|" & GP_FieldValue & "|"
end if
Next
if GP_fieldsStr <> "" then
GP_fieldsStr = Mid(GP_fieldsStr,1,Len(GP_
else
Response.Write "<B>An error has occured during record update!</B><br><br>"
Response.Write "There are no fields to update ...<br>"
Response.Write "If the file upload field is the only field on your form, you should make it required.<br>"
Response.Write "Please correct and <A HREF=""javascript:history.
Response.End
end if
FixFieldsForUpload = GP_fieldsStr
End Function
Function FixColumnsForUpload(GP_fie
Dim GP_counter, GP_Fields, GP_Columns, GP_FieldName, GP_ColumnName, GP_ColumnValue,GP_CurFileN
GP_Fields = Split(GP_fieldsStr, "|")
GP_Columns = Split(GP_columnsStr, "|")
GP_columnsStr = ""
' Get the form values
For GP_counter = LBound(GP_Fields) To UBound(GP_Fields) Step 2
GP_FieldName = LCase(GP_Fields(GP_counter
GP_ColumnName = GP_Columns(GP_counter)
GP_ColumnValue = GP_Columns(GP_counter+1)
if UploadRequest.Exists(GP_Fi
GP_CurFileName = UploadRequest.Item(GP_Fiel
GP_CurContentType = UploadRequest.Item(GP_Fiel
else
GP_CurFileName = ""
GP_CurContentType = ""
end if
if (GP_CurFileName = "" and GP_CurContentType = "") or (GP_CurFileName <> "" and GP_CurContentType <> "") then
GP_columnsStr = GP_columnsStr & GP_ColumnName & "|" & GP_ColumnValue & "|"
end if
Next
if GP_columnsStr <> "" then
GP_columnsStr = Mid(GP_columnsStr,1,Len(GP
end if
FixColumnsForUpload = GP_columnsStr
End Function
</SCRIPT>
ASKER
incResizeAddOn.asp:
<SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
'*** Resize Files After Upload -------------------------- ---------- ---------- -
' Copyright 2001-2002 (c) George Petrov, www.DMXzone.com
'
' Version: 1.0.9
'------------------------- ---------- ---------- ---------- ---------- ---------- ---
sub FitImage_Comp(compType,Dot NetResize, imgFile,ne wImgFile,m axWidth,ma xHeight,Qu ality)
select case compType
case "AUTO"
FitImage_Comp DetectImageComponent(DotNe tResize),D otNetResiz e,imgFile, newImgFile ,maxWidth, maxHeight, Quality
case "PICPROC"
FitImage_PicProc imgFile,newImgFile,maxWidt h,maxHeigh t,Quality
case "ASPJPEG"
FitImage_AspJpeg imgFile,newImgFile,maxWidt h,maxHeigh t,Quality
case "ASPIMAGE"
FitImage_AspImage imgFile,newImgFile,maxWidt h,maxHeigh t,Quality
case "ASPSMART"
FitImage_AspSmart imgFile,newImgFile,maxWidt h,maxHeigh t,Quality
case "IMGWRITER"
FitImage_ImgWriter imgFile,newImgFile,maxWidt h,maxHeigh t,Quality
case "ASPTHUMB"
FitImage_AspThumb imgFile,newImgFile,maxWidt h,maxHeigh t,Quality
case "ASP.NET"
select case DetectDotNetComponent(DotN etResize)
case "DOTNET1"
FitImage_DotNet "Msxml2.ServerXMLHTTP.4.0" ,DotNetRes ize,imgFil e,newImgFi le,maxWidt h,maxHeigh t,Quality
case "DOTNET2"
FitImage_DotNet "Msxml2.ServerXMLHTTP",Dot NetResize, imgFile,ne wImgFile,m axWidth,ma xHeight,Qu ality
case "DOTNET3"
FitImage_DotNet "Microsoft.XMLHTTP",DotNet Resize,img File,newIm gFile,maxW idth,maxHe ight,Quali ty
end select
end select
end sub
function DetectImageComponent(DotNe tResize)
Dim objPictureProcessor, objASPjpeg, AspImage, AspSmart, objImgWriter, objAspThumb, ImageComponent
ImageComponent = ""
if Application("ResizeAutoCom ponent") = "" then
on error resume next
'Check for our own Picture Processor
err.clear
Set objPictureProcessor = Server.CreateObject("COMob jects.NET. PicturePro cessor")
if err.number = 0 then
Set objPictureProcessor = nothing
ImageComponent = "PICPROC"
else
'Check for AspJpeg
err.clear
Set objASPjpeg = Server.CreateObject("Persi ts.Jpeg")
'Response.Write err & " - " & err.number & ":" & err.description & "<br>"
if err.number = 0 then
Set objASPjpeg = nothing
ImageComponent = "ASPJPEG"
else
'Check for AspImage
err.clear
Set AspImage = Server.CreateObject("AspIm age.Image" )
if err.number = 0 then
Set AspImage = nothing
ImageComponent = "ASPIMAGE"
else
'Check for AspSmart
err.clear
Set AspSmart = Server.CreateObject("aspSm artImage.S martImage" )
if err.number = 0 then
Set AspSmartImage = nothing
ImageComponent = "ASPSMART"
else
'Check for ImgWriter
err.clear
Set objImgWriter = Server.CreateObject("softa rtisans.Im ageGen")
if err.number = 0 then
Set objImgWriter = nothing
ImageComponent = "IMGWRITER"
else
'Check for AspThumb
err.clear
Set objAspThumb = Server.CreateObject("briz. AspThumb")
if err.number = 0 then
Set objAspThumb = nothing
ImageComponent = "ASPTHUMB"
else
ImageComponent = DetectDotNetComponent(DotN etResize)
end if
end if
end if
end if
end if
end if
on error goto 0
Application("ResizeAutoCom ponent") = ImageComponent
else 'use application var
ImageComponent = Application("ResizeAutoCom ponent")
end if
if ImageComponent = "" then
Response.Write "SMART IMAGE PROCESSOR ERROR: Can not detect any Resize Server Components!<br>Please install at least the supplied server component. Read the online docs for more info."
Response.End
end if
DetectImageComponent = ImageComponent
end function
function DetectDotNetComponent(DotN etResize)
Dim objHttp, DotNetImageComponent, ResizeComUrl, LastPath
if Application("ResizeDotNetC omponent") = "" then
DotNetImageComponent = ""
ResizeComUrl = "http://" & Request.ServerVariables("S ERVER_NAME ") & Request.ServerVariables("P ATH_INFO")
LastPath = InStrRev(ResizeComUrl,"/")
if LastPath > 0 then
ResizeComUrl = left(ResizeComUrl,Lastpath )
end if
ResizeComUrl = ResizeComUrl & DotNetResize
'Response.Write ResizeComUrl & "<br>"
'Check for ASP.NET 1
on error resume next
err.clear
Set DotNet = Server.CreateObject("Msxml 2.ServerXM LHTTP.4.0" )
if err.number = 0 then
objHttp.open "GET", ResizeComUrl, false
objHttp.Send ""
if trim(objHttp.responseText) <> "" and instr(objHttp.responseText ,"@ Page Language=""C#""") = 0 then
DotNetImageComponent = "DOTNET1"
end if
Set DotNet = nothing
else
'Check for ASP.NET 2
err.clear
Set objHttp = Server.CreateObject("Msxml 2.ServerXM LHTTP")
if err.number = 0 then
on error goto 0
objHttp.open "GET", ResizeComUrl, false
objHttp.Send ""
if trim(objHttp.responseText) <> "" and instr(objHttp.responseText ,"@ Page Language=""C#""") = 0 then
DotNetImageComponent = "DOTNET2"
end if
Set objHttp = nothing
else
'Check for ASP.NET 3
err.clear
Set objHttp = Server.CreateObject("Micro soft.XMLHT TP")
if err.number = 0 then
objHttp.open "GET", ResizeComUrl, false
objHttp.Send ""
if trim(objHttp.responseText) <> "" and instr(objHttp.responseText ,"@ Page Language=""C#""") = 0 then
DotNetImageComponent = "DOTNET3"
end if
Set objHttp = nothing
end if
end if
end if
on error goto 0
Application("ResizeDotNetC omponent") = DotNetImageComponent
else 'use application var
DotNetImageComponent = Application("ResizeDotNetC omponent")
end if
DetectDotNetComponent = DotNetImageComponent
end function
sub FitImage_PicProc(imgFile,n ewImgFile, maxWidth,m axHeight,Q uality)
Dim objPictureProcessor, intNewWidth, intNewHeight
on error resume next
Set objPictureProcessor = Server.CreateObject("COMob jects.NET. PicturePro cessor")
if err.number <> 0 then
Response.Write "ERROR: Picture Processor Server Component is not installed!<br>Please select a different Server Component and try again"
Response.End
end if
on error goto 0
objPictureProcessor.LoadFr omFile imgFile
objPictureProcessor.Qualit y = Quality
calculateNewImageSize objPictureProcessor.Width, objPictureProcessor.Height , maxWidth, maxHeight, intNewWidth, intNewHeight
objPictureProcessor.Resize intNewWidth, intNewHeight
objPictureProcessor.SaveTo FileAsJpeg newImgFile
Set objPictureProcessor = nothing
end sub
sub FitImage_AspJpeg(imgFile,n ewImgFile, maxWidth,m axHeight,Q uality)
Dim objAspJpeg, intNewWidth, intNewHeight
on error resume next
Set objAspJpeg = Server.CreateObject("Persi ts.Jpeg")
if err.number <> 0 then
Response.Write "ERROR: AspJpeg Server Component is not installed!<br>Please select a different Server Component and try again"
Response.End
end if
on error goto 0
objAspJpeg.Open imgFile
objAspJpeg.Quality = Quality
calculateNewImageSize objAspJpeg.OriginalWidth, objAspJpeg.OriginalHeight, maxWidth, maxHeight, intNewWidth, intNewHeight
objAspJpeg.Width = intNewWidth
objAspJpeg.Height = intNewHeight
objAspJpeg.Save newImgFile
Set objAspJpeg = nothing
end sub
sub FitImage_AspImage(imgFile, newImgFile ,maxWidth, maxHeight, Quality)
Dim objAspImage, intNewWidth, intNewHeight
on error resume next
Set objAspImage = Server.CreateObject("AspIm age.Image" )
if err.number <> 0 then
Response.Write "ERROR: AspImage Server Component is not installed!<br>Please select a different Server Component and try again"
Response.End
end if
on error goto 0
objAspImage.LoadImage imgFile
objAspImage.JPEGQuality = Quality
calculateNewImageSize objAspImage.MaxX, objAspImage.MaxY, maxWidth, maxHeight, intNewWidth, intNewHeight
objAspImage.Resize intNewWidth, intNewHeight
objAspImage.FileName = newImgFile
objAspImage.SaveImage
Set objAspImage = nothing
end sub
sub FitImage_AspSmart(imgFile, newImgFile ,maxWidth, maxHeight, Quality)
Dim objAspSmart, intNewWidth, intNewHeight
on error resume next
Set objAspSmart = Server.CreateObject("aspSm artImage.S martImage" )
if err.number <> 0 then
Response.Write "ERROR: AspSmart Server Component is not installed!<br>Please select a different Server Component and try again"
Response.End
end if
on error goto 0
objAspSmart.OpenFile CStr(imgFile)
objAspSmart.Quality = Quality
calculateNewImageSize objAspSmart.OriginalWidth, objAspSmart.OriginalHeight , maxWidth, maxHeight, intNewWidth, intNewHeight
objAspSmart.Resample CInt(intNewWidth), Cint(intNewHeight)
objAspSmart.SaveFile newImgFile
Set objAspSmart = nothing
end sub
sub FitImage_ImgWriter(imgFile ,newImgFil e,maxWidth ,maxHeight ,Quality)
Dim objImgWriter, intNewWidth, intNewHeight
on error resume next
Set objImgWriter = Server.CreateObject("softa rtisans.Im ageGen")
if err.number <> 0 then
Response.Write "ERROR: ImgWriter Server Component is not installed!<br>Please select a different Server Component and try again"
Response.End
end if
on error goto 0
objImgWriter.LoadImage imgFile
objImgWriter.ImageQuality = Quality
calculateNewImageSize objImgWriter.Width, objImgWriter.Height, maxWidth, maxHeight, intNewWidth, intNewHeight
objImgWriter.ResizeImage intNewWidth, intNewHeight
objImgWriter.SaveImage 0,3,newImgFile
Set objImgWriter = nothing
end sub
sub FitImage_AspThumb(imgFile, newImgFile ,maxWidth, maxHeight, Quality)
Dim objAspThumb, intNewWidth, intNewHeight
on error resume next
Set objAspThumb = Server.CreateObject("briz. AspThumb")
if err.number <> 0 then
Response.Write "ERROR: ImgWriter Server Component is not installed!<br>Please select a different Server Component and try again"
Response.End
end if
on error goto 0
objAspThumb.Load imgFile
objAspThumb.EncodingQualit y = Quality
calculateNewImageSize objAspThumb.Width, objAspThumb.Height, maxWidth, maxHeight, intNewWidth, intNewHeight
objAspThumb.Resize intNewWidth, intNewHeight
objAspThumb.Save newImgFile
Set objAspThumb = nothing
end sub
sub FitImage_DotNet(DotNetComp , DotNetResize, imgFile,newImgFile,maxWidt h,maxHeigh t,Quality)
Dim objHttp, ResizeComUrl, ResizeParams, LastPath
ResizeParams = "?f=" & Server.UrlEncode(imgFile) & "&nf=" & Server.UrlEncode(newImgFil e) & "&w=" & maxWidth & "&h=" & maxHeight & "&q=" & Quality
ResizeComUrl = "http://" & Request.ServerVariables("S ERVER_NAME ") & Request.ServerVariables("P ATH_INFO")
LastPath = InStrRev(ResizeComUrl,"/")
if LastPath > 0 then
ResizeComUrl = left(ResizeComUrl,Lastpath )
end if
ResizeComUrl = ResizeComUrl & DotNetResize & ResizeParams
on error resume next
set objHttp = Server.CreateObject(DotNet Comp)
if err.number <> 0 then
Response.Write "ERROR: ASP.NET (" & DotNetComp & ") is not installed!<br>Please select a different Server Component and try again"
Response.End
end if
on error goto 0
objHttp.open "GET", ResizeComUrl, false
objHttp.Send ""
' Check notification validation
if (objHttp.status <> 200 ) then
' HTTP error handling
Response.Write "HTTP ERROR: " & objHttp.status & "<br>"
Response.Write "Returned:<br>" & objHttp.responseText
elseif (objHttp.responseText = "DONE") then
else
if trim(objHttp.responseText) = "" or instr(objHttp.responseText ,"@ Page Language=""C#""") > 0 then
Response.Write "DOT NET Unsupported"
end if
end if
Set objHttp = Nothing
end sub
sub calculateNewImageSize(curW idth, curHeight, maxWidth, maxHeight, newWidth, newHeight)
if maxWidth < curWidth or maxHeight < curHeight then
if maxWidth >= maxHeight then
newWidth = CInt(maxHeight*(curWidth/c urHeight))
newHeight = maxHeight
else
newWidth = maxWidth
newHeight = CInt(maxWidth*(curHeight/c urWidth))
end if
if newWidth > maxWidth then
newWidth = maxWidth
newHeight = CInt(maxWidth*(curHeight/c urWidth))
end if
if newHeight > maxHeight then
newWidth = CInt(maxHeight*(curWidth/c urHeight))
newHeight = maxHeight
end if
else
newWidth = curWidth
newHeight = curHeight
end if
end sub
Sub ResizeUploadedFiles(RUF_Co mponent, RUF_DotNetResize, RUF_path, RUF_Suffix, RUF_maxWidth, RUF_maxHeight, RUF_Quality, RUF_RemoveOrig)
Dim RUF_keys, RUF_i, RUF_curKey, RUF_fileName, RUF_fso, RUF_newFileName, RUF_curPath, RUF_curName, RUF_curExt, RUF_lastPos, RUF_orgCurPath
if RUF_path <> "" and right(RUF_path,1) <> "/" then RUF_path = RUF_path & "/"
Set RUF_fso = CreateObject("Scripting.Fi leSystemOb ject")
RUF_maxWidth = Cint(RUF_maxWidth)
RUF_maxHeight = Cint(RUF_maxHeight)
RUF_keys = UploadRequest.Keys
for RUF_i = 0 to UploadRequest.Count - 1
RUF_curKey = RUF_keys(RUF_i)
if UploadRequest.Exists(RUF_c urKey) then
if UploadRequest.Item(RUF_cur Key).Exist s("FileNam e") then
if UploadRequest.Item(RUF_cur Key).Item( "FileName" ) <> "" then
RUF_fileName = UploadRequest.Item(RUF_cur Key).Item( "Value")
if RUF_fileName <> "" then
RUF_curPath = "" : RUF_curName = "" : RUF_curExt = ""
RUF_lastPos = InStrRev(RUF_fileName,"/")
if RUF_lastPos > 0 then
RUF_curPath = mid(RUF_fileName,1,RUF_las tPos)
RUF_curName = mid(RUF_fileName,RUF_lastP os+1,Len(R UF_fileNam e)-RUF_las tPos)
RUF_fileName = UploadRequest.Item(RUF_cur Key).Item( "FileName" )
else
RUF_curName = RUF_fileName
end if
RUF_lastPos = InStrRev(RUF_curName,".")
if RUF_lastPos > 0 then
RUF_curExt = mid(RUF_curName,RUF_lastPo s+1,Len(RU F_curName) -RUF_lastP os)
RUF_curName = mid(RUF_curName,1,RUF_last Pos-1)
end if
RUF_curExt = LCase(RUF_curExt)
RUF_orgCurPath = RUF_curPath
if RUF_curPath = "" then RUF_curPath = RUF_path
if RUF_fso.FileExists(Server. MapPath(RU F_curPath & RUF_fileName)) then
if RUF_curExt = "jpg" or RUF_curExt = "jpeg" or RUF_curExt = "gif" or RUF_curExt = "bmp" or RUF_curExt = "png" or RUF_curExt = "pgm" or RUF_curExt = "tga" or RUF_curExt = "tiff" or RUF_curExt = "jfif" then
RUF_newFileName = RUF_curName & RUF_Suffix & ".jpg"
FitImage_Comp RUF_Component, RUF_DotNetResize, Server.MapPath(RUF_CurPath & RUF_fileName), Server.MapPath(RUF_curPath & RUF_newFileName), RUF_maxWidth, RUF_maxHeight, RUF_Quality
if RUF_RemoveOrig then
if LCase(RUF_fileName) <> LCase(RUF_newFileName) then
RUF_fso.DeleteFile Server.MapPath(RUF_curPath & RUF_fileName)
end if
if RUF_orgCurPath <> "" then
UploadRequest.Item(RUF_cur Key).Item( "Value") = RUF_orgCurPath & RUF_newFileName
else
UploadRequest.Item(RUF_cur Key).Item( "Value") = RUF_newFileName
end if
UploadRequest.Item(RUF_cur Key).Item( "FileName" ) = RUF_newFileName
end if
end if
end if
end if
end if
end if
end if
next
End Sub
</SCRIPT>
<SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
'*** Resize Files After Upload --------------------------
' Copyright 2001-2002 (c) George Petrov, www.DMXzone.com
'
' Version: 1.0.9
'-------------------------
sub FitImage_Comp(compType,Dot
select case compType
case "AUTO"
FitImage_Comp DetectImageComponent(DotNe
case "PICPROC"
FitImage_PicProc imgFile,newImgFile,maxWidt
case "ASPJPEG"
FitImage_AspJpeg imgFile,newImgFile,maxWidt
case "ASPIMAGE"
FitImage_AspImage imgFile,newImgFile,maxWidt
case "ASPSMART"
FitImage_AspSmart imgFile,newImgFile,maxWidt
case "IMGWRITER"
FitImage_ImgWriter imgFile,newImgFile,maxWidt
case "ASPTHUMB"
FitImage_AspThumb imgFile,newImgFile,maxWidt
case "ASP.NET"
select case DetectDotNetComponent(DotN
case "DOTNET1"
FitImage_DotNet "Msxml2.ServerXMLHTTP.4.0"
case "DOTNET2"
FitImage_DotNet "Msxml2.ServerXMLHTTP",Dot
case "DOTNET3"
FitImage_DotNet "Microsoft.XMLHTTP",DotNet
end select
end select
end sub
function DetectImageComponent(DotNe
Dim objPictureProcessor, objASPjpeg, AspImage, AspSmart, objImgWriter, objAspThumb, ImageComponent
ImageComponent = ""
if Application("ResizeAutoCom
on error resume next
'Check for our own Picture Processor
err.clear
Set objPictureProcessor = Server.CreateObject("COMob
if err.number = 0 then
Set objPictureProcessor = nothing
ImageComponent = "PICPROC"
else
'Check for AspJpeg
err.clear
Set objASPjpeg = Server.CreateObject("Persi
'Response.Write err & " - " & err.number & ":" & err.description & "<br>"
if err.number = 0 then
Set objASPjpeg = nothing
ImageComponent = "ASPJPEG"
else
'Check for AspImage
err.clear
Set AspImage = Server.CreateObject("AspIm
if err.number = 0 then
Set AspImage = nothing
ImageComponent = "ASPIMAGE"
else
'Check for AspSmart
err.clear
Set AspSmart = Server.CreateObject("aspSm
if err.number = 0 then
Set AspSmartImage = nothing
ImageComponent = "ASPSMART"
else
'Check for ImgWriter
err.clear
Set objImgWriter = Server.CreateObject("softa
if err.number = 0 then
Set objImgWriter = nothing
ImageComponent = "IMGWRITER"
else
'Check for AspThumb
err.clear
Set objAspThumb = Server.CreateObject("briz.
if err.number = 0 then
Set objAspThumb = nothing
ImageComponent = "ASPTHUMB"
else
ImageComponent = DetectDotNetComponent(DotN
end if
end if
end if
end if
end if
end if
on error goto 0
Application("ResizeAutoCom
else 'use application var
ImageComponent = Application("ResizeAutoCom
end if
if ImageComponent = "" then
Response.Write "SMART IMAGE PROCESSOR ERROR: Can not detect any Resize Server Components!<br>Please install at least the supplied server component. Read the online docs for more info."
Response.End
end if
DetectImageComponent = ImageComponent
end function
function DetectDotNetComponent(DotN
Dim objHttp, DotNetImageComponent, ResizeComUrl, LastPath
if Application("ResizeDotNetC
DotNetImageComponent = ""
ResizeComUrl = "http://" & Request.ServerVariables("S
LastPath = InStrRev(ResizeComUrl,"/")
if LastPath > 0 then
ResizeComUrl = left(ResizeComUrl,Lastpath
end if
ResizeComUrl = ResizeComUrl & DotNetResize
'Response.Write ResizeComUrl & "<br>"
'Check for ASP.NET 1
on error resume next
err.clear
Set DotNet = Server.CreateObject("Msxml
if err.number = 0 then
objHttp.open "GET", ResizeComUrl, false
objHttp.Send ""
if trim(objHttp.responseText)
DotNetImageComponent = "DOTNET1"
end if
Set DotNet = nothing
else
'Check for ASP.NET 2
err.clear
Set objHttp = Server.CreateObject("Msxml
if err.number = 0 then
on error goto 0
objHttp.open "GET", ResizeComUrl, false
objHttp.Send ""
if trim(objHttp.responseText)
DotNetImageComponent = "DOTNET2"
end if
Set objHttp = nothing
else
'Check for ASP.NET 3
err.clear
Set objHttp = Server.CreateObject("Micro
if err.number = 0 then
objHttp.open "GET", ResizeComUrl, false
objHttp.Send ""
if trim(objHttp.responseText)
DotNetImageComponent = "DOTNET3"
end if
Set objHttp = nothing
end if
end if
end if
on error goto 0
Application("ResizeDotNetC
else 'use application var
DotNetImageComponent = Application("ResizeDotNetC
end if
DetectDotNetComponent = DotNetImageComponent
end function
sub FitImage_PicProc(imgFile,n
Dim objPictureProcessor, intNewWidth, intNewHeight
on error resume next
Set objPictureProcessor = Server.CreateObject("COMob
if err.number <> 0 then
Response.Write "ERROR: Picture Processor Server Component is not installed!<br>Please select a different Server Component and try again"
Response.End
end if
on error goto 0
objPictureProcessor.LoadFr
objPictureProcessor.Qualit
calculateNewImageSize objPictureProcessor.Width,
objPictureProcessor.Resize
objPictureProcessor.SaveTo
Set objPictureProcessor = nothing
end sub
sub FitImage_AspJpeg(imgFile,n
Dim objAspJpeg, intNewWidth, intNewHeight
on error resume next
Set objAspJpeg = Server.CreateObject("Persi
if err.number <> 0 then
Response.Write "ERROR: AspJpeg Server Component is not installed!<br>Please select a different Server Component and try again"
Response.End
end if
on error goto 0
objAspJpeg.Open imgFile
objAspJpeg.Quality = Quality
calculateNewImageSize objAspJpeg.OriginalWidth, objAspJpeg.OriginalHeight,
objAspJpeg.Width = intNewWidth
objAspJpeg.Height = intNewHeight
objAspJpeg.Save newImgFile
Set objAspJpeg = nothing
end sub
sub FitImage_AspImage(imgFile,
Dim objAspImage, intNewWidth, intNewHeight
on error resume next
Set objAspImage = Server.CreateObject("AspIm
if err.number <> 0 then
Response.Write "ERROR: AspImage Server Component is not installed!<br>Please select a different Server Component and try again"
Response.End
end if
on error goto 0
objAspImage.LoadImage imgFile
objAspImage.JPEGQuality = Quality
calculateNewImageSize objAspImage.MaxX, objAspImage.MaxY, maxWidth, maxHeight, intNewWidth, intNewHeight
objAspImage.Resize intNewWidth, intNewHeight
objAspImage.FileName = newImgFile
objAspImage.SaveImage
Set objAspImage = nothing
end sub
sub FitImage_AspSmart(imgFile,
Dim objAspSmart, intNewWidth, intNewHeight
on error resume next
Set objAspSmart = Server.CreateObject("aspSm
if err.number <> 0 then
Response.Write "ERROR: AspSmart Server Component is not installed!<br>Please select a different Server Component and try again"
Response.End
end if
on error goto 0
objAspSmart.OpenFile CStr(imgFile)
objAspSmart.Quality = Quality
calculateNewImageSize objAspSmart.OriginalWidth,
objAspSmart.Resample CInt(intNewWidth), Cint(intNewHeight)
objAspSmart.SaveFile newImgFile
Set objAspSmart = nothing
end sub
sub FitImage_ImgWriter(imgFile
Dim objImgWriter, intNewWidth, intNewHeight
on error resume next
Set objImgWriter = Server.CreateObject("softa
if err.number <> 0 then
Response.Write "ERROR: ImgWriter Server Component is not installed!<br>Please select a different Server Component and try again"
Response.End
end if
on error goto 0
objImgWriter.LoadImage imgFile
objImgWriter.ImageQuality = Quality
calculateNewImageSize objImgWriter.Width, objImgWriter.Height, maxWidth, maxHeight, intNewWidth, intNewHeight
objImgWriter.ResizeImage intNewWidth, intNewHeight
objImgWriter.SaveImage 0,3,newImgFile
Set objImgWriter = nothing
end sub
sub FitImage_AspThumb(imgFile,
Dim objAspThumb, intNewWidth, intNewHeight
on error resume next
Set objAspThumb = Server.CreateObject("briz.
if err.number <> 0 then
Response.Write "ERROR: ImgWriter Server Component is not installed!<br>Please select a different Server Component and try again"
Response.End
end if
on error goto 0
objAspThumb.Load imgFile
objAspThumb.EncodingQualit
calculateNewImageSize objAspThumb.Width, objAspThumb.Height, maxWidth, maxHeight, intNewWidth, intNewHeight
objAspThumb.Resize intNewWidth, intNewHeight
objAspThumb.Save newImgFile
Set objAspThumb = nothing
end sub
sub FitImage_DotNet(DotNetComp
Dim objHttp, ResizeComUrl, ResizeParams, LastPath
ResizeParams = "?f=" & Server.UrlEncode(imgFile) & "&nf=" & Server.UrlEncode(newImgFil
ResizeComUrl = "http://" & Request.ServerVariables("S
LastPath = InStrRev(ResizeComUrl,"/")
if LastPath > 0 then
ResizeComUrl = left(ResizeComUrl,Lastpath
end if
ResizeComUrl = ResizeComUrl & DotNetResize & ResizeParams
on error resume next
set objHttp = Server.CreateObject(DotNet
if err.number <> 0 then
Response.Write "ERROR: ASP.NET (" & DotNetComp & ") is not installed!<br>Please select a different Server Component and try again"
Response.End
end if
on error goto 0
objHttp.open "GET", ResizeComUrl, false
objHttp.Send ""
' Check notification validation
if (objHttp.status <> 200 ) then
' HTTP error handling
Response.Write "HTTP ERROR: " & objHttp.status & "<br>"
Response.Write "Returned:<br>" & objHttp.responseText
elseif (objHttp.responseText = "DONE") then
else
if trim(objHttp.responseText)
Response.Write "DOT NET Unsupported"
end if
end if
Set objHttp = Nothing
end sub
sub calculateNewImageSize(curW
if maxWidth < curWidth or maxHeight < curHeight then
if maxWidth >= maxHeight then
newWidth = CInt(maxHeight*(curWidth/c
newHeight = maxHeight
else
newWidth = maxWidth
newHeight = CInt(maxWidth*(curHeight/c
end if
if newWidth > maxWidth then
newWidth = maxWidth
newHeight = CInt(maxWidth*(curHeight/c
end if
if newHeight > maxHeight then
newWidth = CInt(maxHeight*(curWidth/c
newHeight = maxHeight
end if
else
newWidth = curWidth
newHeight = curHeight
end if
end sub
Sub ResizeUploadedFiles(RUF_Co
Dim RUF_keys, RUF_i, RUF_curKey, RUF_fileName, RUF_fso, RUF_newFileName, RUF_curPath, RUF_curName, RUF_curExt, RUF_lastPos, RUF_orgCurPath
if RUF_path <> "" and right(RUF_path,1) <> "/" then RUF_path = RUF_path & "/"
Set RUF_fso = CreateObject("Scripting.Fi
RUF_maxWidth = Cint(RUF_maxWidth)
RUF_maxHeight = Cint(RUF_maxHeight)
RUF_keys = UploadRequest.Keys
for RUF_i = 0 to UploadRequest.Count - 1
RUF_curKey = RUF_keys(RUF_i)
if UploadRequest.Exists(RUF_c
if UploadRequest.Item(RUF_cur
if UploadRequest.Item(RUF_cur
RUF_fileName = UploadRequest.Item(RUF_cur
if RUF_fileName <> "" then
RUF_curPath = "" : RUF_curName = "" : RUF_curExt = ""
RUF_lastPos = InStrRev(RUF_fileName,"/")
if RUF_lastPos > 0 then
RUF_curPath = mid(RUF_fileName,1,RUF_las
RUF_curName = mid(RUF_fileName,RUF_lastP
RUF_fileName = UploadRequest.Item(RUF_cur
else
RUF_curName = RUF_fileName
end if
RUF_lastPos = InStrRev(RUF_curName,".")
if RUF_lastPos > 0 then
RUF_curExt = mid(RUF_curName,RUF_lastPo
RUF_curName = mid(RUF_curName,1,RUF_last
end if
RUF_curExt = LCase(RUF_curExt)
RUF_orgCurPath = RUF_curPath
if RUF_curPath = "" then RUF_curPath = RUF_path
if RUF_fso.FileExists(Server.
if RUF_curExt = "jpg" or RUF_curExt = "jpeg" or RUF_curExt = "gif" or RUF_curExt = "bmp" or RUF_curExt = "png" or RUF_curExt = "pgm" or RUF_curExt = "tga" or RUF_curExt = "tiff" or RUF_curExt = "jfif" then
RUF_newFileName = RUF_curName & RUF_Suffix & ".jpg"
FitImage_Comp RUF_Component, RUF_DotNetResize, Server.MapPath(RUF_CurPath
if RUF_RemoveOrig then
if LCase(RUF_fileName) <> LCase(RUF_newFileName) then
RUF_fso.DeleteFile Server.MapPath(RUF_curPath
end if
if RUF_orgCurPath <> "" then
UploadRequest.Item(RUF_cur
else
UploadRequest.Item(RUF_cur
end if
UploadRequest.Item(RUF_cur
end if
end if
end if
end if
end if
end if
end if
next
End Sub
</SCRIPT>
Orroland--
I am so sorry! I was making a joke about requesting the code to eliminate human error!!!
If this code works well for all of your other users, I can only imagine that the issue is environmental.
FtB
I am so sorry! I was making a joke about requesting the code to eliminate human error!!!
If this code works well for all of your other users, I can only imagine that the issue is environmental.
FtB
ASKER
Sorry - human error at my end!
Giving fritz the points because he did answer the question "forms don't timeout"
Giving fritz the points because he did answer the question "forms don't timeout"
Thank you and sorry that I couldn't be of more help.
FtB
FtB
http://www.dmxzone.com/ShowDetail.asp?NewsId=477
FtB