主题:  求助:关于pure asp upload 的一些问题

longzaitianya

职务:普通成员
等级:1
金币:0.0
发贴:1
注册:2005/5/1 11:37:02
#12005/5/1 14:19:01
我用的2。09在mx中使用,单独用pureaspupload的时候没什么问题,但加了插入数据库行为时报错,错误如下
Microsoft VBScript 编译器错误 错误 '800a03f6'

缺少 'End'

/iisHelp/common/500-100.asp,行242

请求对象 错误 'ASP 0206 : 80004005'

不能调用 BinaryRead

/untitled.asp,行29

使用 Request.Form 后不能调用 BinaryRead。
不管是先加insert还是后加,都这样,我看了代码,没有发现有request.form,还请高手指点,谢谢,下面是代码
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="Connections/conn.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: """""", Extensions: "GIF,JPG,JPEG,BMP,PNG", Form: form1, Redirect: "", "file", "500", "over", "true", "", "" , "", "", "", "", "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 "<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 = 600

RequestBin = Request.BinaryRead(Request.TotalBytes)
Set UploadRequest = CreateObject("Scripting.Dictionary"
BuildUploadRequest RequestBin, """""", "file", "500", "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
'------------------------------------------------------------------------------
%>
<%
' *** 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 & "?" & Server.HTMLEncode(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") = "form1" Then

MM_editConnection = MM_conn_STRING
MM_editTable = "test"
MM_editRedirectUrl = "index.asp"
MM_fieldsStr = "img|value"
MM_columnsStr = "tphoto|',none,''"

' 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
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<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('必须选择文件!');document.MM_returnvalue = false;field.focus();return;}
} else {
if(extensions != '' && !re.test(field.value)) {
alert('您选择的文件类型不能上传。\n支持上传的文件类型包括: ' + extensions + '.\n请选择正确的文件类型。');
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('上传的图片尺寸太小!\n最小应该为: ' + img.minWidth + ' x ' + img.minHeight); return;}
if ((img.maxWidth != '' && img.width > img.maxWidth) || (img.maxHeight != '' && img.height > img.maxHeight)) {
alert('上传的图片尺寸太大!\n最大应该为: ' + img.maxWidth + ' x ' + img.maxHeight); return;}
if (img.sizeLimit != '' && img.fileSize > img.sizeLimit) {
alert('上传的图片文件体积太大!\n最大应该为: ' + (img.sizeLimit/1024) + ' KB'); return;}
if (img.saveWidth != '') document.PU_uploadForm[img.saveWidth].value = img.width;
if (img.saveHeight != '') document.PU_uploadForm[img.saveHeight].value = img.height;
document.MM_returnvalue = true;
} }

function checkImageDimensions(field,sizeL,minW,minH,maxW,maxH,saveW,saveH) { //v2.09
if (!document.layers) {
var isNS6 = (!document.all && document.getElementById ? true : false);
document.MM_returnvalue = false; var imgURL = 'file:///' + field.value.replace(/\\/gi,'/').replace(/:/gi,'|').replace(/"/gi,'').replace(/^\//,'');
if (!field.gp_img || (field.gp_img && field.gp_img.src != imgURL) || isNS6) {field.gp_img = new Image();
         with (field) {gp_img.sizeLimit = sizeL*1024; gp_img.minWidth = minW; gp_img.minHeight = minH; gp_img.maxWidth = maxW; gp_img.maxHeight = maxH;
     gp_img.saveWidth = saveW; gp_img.saveHeight = saveH; gp_img.onload = showImageDimensions; gp_img.src = imgURL; }
     } else showImageDimensions(field.gp_img);}
}
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<form ACTION="<%=MM_editAction%>" METHOD="post" enctype="multipart/form-data" name="form1" onSubmit="checkFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',true,500,'','','','','','');return document.MM_returnvalue">
<input name="img" type="file" id="img" onChange="checkOneFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',true,500,'','','','','','')">
<input type="submit" name="Submit" value="提交">
<input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>