Mit upload script vil vist ikke opdatere?
Hej.Hvis jeg prøver at uploade et billede, med mit upload script kommer denne fejl:
ADODB.Recordset error '800a0cb3'
Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype.
/upload.asp, line 106
Det er mit script:
<%
Response.expires = 0
Response.expiresabsolute = Now() - 1
Response.addHeader "pragma", "no-cache"
Response.addHeader "cache-control", "private"
Response.CacheControl = "no-cache"
response.buffer = true
Response.Clear
Sub BuildUploadRequest(RequestBin)
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos = InstrB(1,RequestBin,boundary)
Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Dictionary")
Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
Pos = InstrB(Pos,RequestBin,getByteString("name="))
PosBeg = Pos+6
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename="))
PosBound = InstrB(PosEnd,RequestBin,boundary)
If PosFile<>0 AND (PosFile<PosBound) Then
PosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "FileName", FileName
Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
PosBeg = Pos+14
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "ContentType",ContentType
PosBeg = PosEnd+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
Else
Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
PosBeg = Pos+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
End If
UploadControl.Add "Value" , Value
UploadRequest.Add name, UploadControl
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
Loop
End Sub
Function getByteString(StringStr)
For i = 1 to Len(StringStr)
char = Mid(StringStr,i,1)
getByteString = getByteString & chrB(AscB(char))
Next
End Function
Function getString(StringBin)
getString =""
For intCount = 1 to LenB(StringBin)
getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
Next
End Function
key = request.querystring("key")
If key = 1 then
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest(RequestBin)
contentType = UploadRequest.Item("blob").Item("ContentType")
filepathname = UploadRequest.Item("blob").Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
Dim AllowedExt(2)
AllowedExt(0) = "jpg"
AllowedExt(1) = "gif"
AllowedExt(2) = "png"
Extension = Right(Filename, Len(Filename) - InStrRev(Filename, ".", -1, 1))
Godkendt = 0
FileTypes = ""
For each x in AllowedExt
If FileTypes = "" Then
FileTypes = x
Else
FileTypes = FileTypes + ", " + x
End If
If LCase(Extension) = LCase(x) Then Godkendt=1
Next
If Godkendt = 1 then
value = UploadRequest.Item("blob").Item("Value")
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
Set MyFile = ScriptObject.CreateTextFile(Server.mappath(""&filename))
For i = 1 to LenB(value)
MyFile.Write chr(AscB(MidB(value,i,1)))
Next
MyFile.Close
Set con = Server.CreateObject("ADODB.Connection")
con.Open "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=testing;UID=root;PASSWORD=root"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT * FROM upload",con
rs.AddNew
rs("file") = filename
rs.Update
rs.Close
Set rs = Nothing
con.Close
Set con = Nothing
Response.Clear
Response.Redirect "upload_list.asp"
End If
End if
%>
<html>
<head>
<title>Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
function SetCookie (name, value) {var argv = SetCookie.arguments;var argc = SetCookie.arguments.length;var expires = (argc > 2) ? argv[2] : null;var path = (argc > 3) ? argv[3] : null;var domain = (argc > 4) ? argv[4] : null;var secure = (argc > 5) ? argv[5] : false;document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "")}
function set_name(form) {var expdate = new Date ();expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
}
</script>
</head>
<body bgcolor="#FFFFFF" leftmargin=0 topmargin=0 marginheight=0 marginwidth=0>
<br>
<span style="position: absolute; top:+10px;left: +10px;letter-spacing: +0px;font: 20px Verdana, Arial;font-weight: bold;">Upload billede</span>
<p> </p>
<table width="900" height="76" border="0">
<tr>
<td width="369" align="right"><table width="329" border="0">
<tr>
<td height="23"><font size="2">Find din billede og tryk på upload: </font></td>
</tr>
</table>
<br></td>
<td width="515"><table align="left">
<tr>
<td width="311"><form METHOD='Post' ENCTYPE='multipart/form-data' ACTION='upload.asp?key=1' id='form3' name='form3' onSubmit="return set_name(this.form);">
<br>
<input type="file" name="blob" class="input">
<br>
<input TYPE="submit" value="Upload" NAME="Enter">
</form></td>
</tr>
</table></td>
</tr>
</table>
<% If Godkendt = 0 And Key = 1 Then Response.Write("Der kan kun uploades filer som slutter på: " & FileTypes) %>
</body>
</html>
