webForumDet fria alternativet

Ladda upp bilder med fupload.

ASP

2 svar · 290 visningar · startad av ulsy

Medlem sedan aug. 2002121 inlägg
Frågan#1

Har problem med att få fupload att fungera.
Vill använda detta för att ladda bilder till en MySQL-bas som består av fälten:
BLOB_ID tinyint
BLOBa longblob

Får felmeddelandet: Exception when loading BLOB field.

Anväder följande kod:

<%@LANGUAGE="VBSCRIPT"%>

<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>File Upload Test</TITLE>
</HEAD>
<BODY>
<BR>
<BR>
<CENTER>
<%
If Request.querystring("Status") = 1 Then
Set oUpload = Server.CreateObject("ASPPW.Upload")
'oUpload.UserDiskQuota= 20 * 1024 * 1024
oUpload.RejectEmptyExtension = No
oUpload.FileExtensionList "txt", "gif" ,"jpg", "*" 'remove '*', if you don't allow all types
oUpload.RegistrationCode = ""
oUpload.RemoveUploadedFilesOnError = YES

'Save uploaded file here.
'oUpload.UpLoadPath = 

'\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
'Uncomment following lines to save files with a prefix or suffix
'for example, saving abc.gif as Prefix_abc_Suffix.gif.
'oUpload.SaveFileWithPrefix="Prefix\_"
'oUpload.SaveFileWithSuffix="\_Suffix"
'\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

'***************************************************************
'Uncomment following lines to upload a file into a BLOB field.
'Note: BLOB uploading doesn't support uploading multiple files
' at a single time.
' Microsoft ADO is required.
oUpload.BLOBFieldName = "BLOBa"
oUpload.LoadIntoBLOBOnly = True
oUpload.BLOBSQL ="SELECT BLOBa FROM BLOB_TBL WHERE BLOB_ID=1"
oUpload.CONNECTIONSTRING= "driver=MySQL;DB=namn på basen;SERVER=server.se;UID=admin;PWD=********"
'***************************************************************

i = oUpload.Upload
Select Case i
    case  1
        sMsg = "File uploading ends normally."
    Case -4
        sMsg = "User's disk quota full."
    Case -5
        sMsg = "Path on server for uploading not found or invalid."
    Case -6
        sMsg = "A file type for uploading is not allowed."
    Case -7
        sMsg = "Uploading exception."
    Case -8
        sMsg = "File access failure."  'Check your NTFS directory permission, Add R/W/D to IUSR_xxx 
    Case -9
        sMsg = "Bad Content Header."
    Case -11
        sMsg = "Exception when loading BLOB field."
    case else
        sMsg = "Exception. Error Code is: " & i & "."
  End Select

Response.write "\<H1\>" + sMsg + "\</H1\>"
If oUpload.GetLastErrNum \<\> 0 Then
    Response.write  "Error: " & oUpload.GetLastErrDescription  & "\<BR\>"
End if

Response.write CStr(oUpload.NumofUploadedFiles) + " file(s) uploaded. "

If oUpload.LoadIntoBLOBOnly = false Then
    Response.write CStr(oUpload.UserDiskSpaceLeft)  + " bytes left for more uploading.\<BR\>"
End if

Set oForm  = oUpload.Form              'return a Collection
Set oFiles = oUpload.UploadedFileInfo  'return a Collection
'response.write oFiles.count           'Sample operation to a collection
'Set item = oFiles.item(1)             'Sample operation to a collection

%>
<table width="100%" border="1">
<tr>
<td nowrap>Uploaded File's Name</td>
<td nowrap>Uploaded File's Length</td>
<td nowrap>FORM Item Name</td>
<td nowrap>(Optional) Caption</td>
<td nowrap>Client Side Path</td>
</tr>
<% for each file in oFiles %>
<tr>
<td nowrap><%=file.filename%></td>
<td nowrap><%=file.filelen%></td>
<td nowrap><%=file.formname%></td>
<td nowrap><%=oForm(file.formname)%></td>
<td nowrap><%=file.clipath%></td>
</tr>
<% next %>
</table>
<% 'Another demo
Set file = oFiles("uplfile1")
if file.filename <> "" then
response.write oFiles("uplfile1").formname & ": "
response.write file.filename & " "
response.write CStr(file.filelen) & " bytes "
response.write oForm(file.formname) & "<br>"
end if
Set file = nothing
%>
<%
'***************************************************************
'It is easy to delete the uploaded stuff.
'if oFiles.Count >0 then oUpload.DeleteFile server.mappath("/") & "\test\" & oFiles(1).filename
'oUpload.DeleteDir server.mappath("/") & "\test"
'***************************************************************

Set oFiles = nothing

%>
<%
'Following codes show you how you how to fetch <FORM> items.
'This COM component uses the BinaryRead method, thus
'you can not fetch form items by using request.form("What").
'According to Microsoft IIS document, this will cause an error.
%>
<p>
<H2>Demonstration of fetching form items: </H2>
<!-- Method 1 -->
<%
response.write "oForm(""Org_Code"").value: " & oForm("Org_Code").value
'response.write "oForm(""Org_Code"").value: " & oForm("Org_Code") 'Same as above
'Set item = oForm("Org_Code")
'Response.write item.value
%>
<!-- Method 2 -->
<table width="80%" border="1">
<tr>
<td>Form Item Name</td>
<td>Form Item Value</td>
</tr>
<% for each item in oForm %>
<tr>
<td><%=item.name%></td>
<td><%=item.value%></td>
</tr>
<% next %>
</table>
<%
Set oForm = nothing
Set oUpload = nothing
End if
%>
<FORM NAME=up ACTION="fupload.asp?Status=1" METHOD="POST" ENCTYPE="multipart/form-data">
<!-- You can specify the filenames for uploaded files as below
ServerName1 ...99
<FORM NAME=up ACTION="fupload.asp?Status=1&ServerName1='aa 1.gif'&ServerName2='bb 2.gif'" METHOD="POST" ENCTYPE="multipart/form-data">
-->
<H1>Upload Files</H1>
<BR>
<!-- Remove below form item if you don't need it. -->
<INPUT TYPE=HIDDEN SIZE=36 NAME="Org_Code" VALUE="Research Dept.">
<!-- Remove above form item if you don't need it. -->
<!-- Remove below form item if you don't need it. -->
<INPUT TYPE=HIDDEN SIZE=36 NAME="uplfile1" VALUE="From Research Dept.">
<!-- Remove above form item if you don't need it. -->
<!-- Remove below form item if you don't need it. -->
<!--INPUT TYPE=HIDDEN SIZE=36 NAME="uplfile2" VALUE="From Development Dept.">
<!-- Remove above form item if you don't need it. -->
<INPUT TYPE=file SIZE=36 NAME="uplfile1">
<!-- ServerName1 -->
<P>
<!-- You can add more if you want to upload more files at a single time -->
<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE=" Upload ">
<p align="right"><a href="http://www.dalun.com"><font face="Verdana, Arial" size="1">Dalun
Software, Inc. </font></a>
</FORM>
</CENTER>
</BODY>
</HTML>

Mycket tacksam för svar!

:q
redigerat password

Medlem sedan dec. 200012 464 inlägg
#2

Och så korspostar vi inte.

Medlem sedan feb. 200112 078 inlägg
266 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e
125 ms — deklarationer (db)
0 ms — hämta statistik (cache)
138 ms — hämta tråd, inlägg och bilagor (db)
125 ms — ändringar (db)