02. marts 2004 - 10:08Der er
6 kommentarer og 1 løsning
Viser kun 50% af de oploadede billeder
Hej Jeg har en lille eshop hvor jeg har et problem med visning af oploadede JPG filer. I ca. 2/3 tilfælde går det fint, billederne vises som de skal, men i resten af tilfældene går det galt, så kan disse ikke vises. Billederne bliver oploadet korrekt og e er indført i databasen, men kan alligevel ikke vises. Hvis jeg så begynder at gøre dem større eller mindre lykkedes det som regelen, men der skal 5 - 7 forsøg til før det lykkedes - hvis det lykkedes!!!. Normalt er størrelsen ligegyldig - de er fra 75kb til 256kb!! og kan alligevel vises!! Desværre ved jeg ikke nok til ASP så jeg kan sige i hvilken fil problemet må ligge, men logikken siger mig at det må være Showimage.asp som er problemet - er det ikke det, så lad mig det vide så skal kopiere det ind.
Her er Showimage.asp: <% DIM Filename Filename = Request.QueryString("Filename") If UCase(Right(Filename,3)) = "JPG" Then Response.ContentType = "image/jpeg" Else Response.ContentType = "image/gif" End If Server.Transfer ("../database/"&Filename) %>
Støv, fibre og metalliske partikler kan påvirke både uptime, levetid og driftssikkerhed. Derfor arbejder flere datacentre systematisk med contamination control.
function MM_goToURL() { //v3.0 var i, args=MM_goToURL.arguments; document.MM_returnValue = false; for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'"); }
Dette? <% Sub BuildUploadRequest(RequestBin) 'Get the boundary PosBeg = 1 PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13))) if PosEnd = 0 then Response.Write "<b>Form was submitted with no ENCTYPE=""multipart/form-data""</b><br>" Response.Write "Please correct the form attributes and try again." Response.End end if boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg) boundaryPos = InstrB(1,RequestBin,boundary) 'Get all data inside the boundaries Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--"))) 'Members variable of objects are put in a dictionary object Dim UploadControl Set UploadControl = CreateObject("Scripting.Dictionary") 'Get an object name 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) '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,getByteString(chr(34))) FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg)) FileName = Mid(FileName,InStrRev(FileName,"\")+1) 'Add filename to dictionary object UploadControl.Add "FileName", FileName Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:")) PosBeg = Pos+14 PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13))) 'Add content-type to dictionary object ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg)) UploadControl.Add "ContentType",ContentType 'Get content of object PosBeg = PosEnd+4 PosEnd = InstrB(PosBeg,RequestBin,boundary)-2 Value = FileName ValueBeg = PosBeg-1 ValueLen = PosEnd-Posbeg Else 'Get content of object Pos = InstrB(Pos,RequestBin,getByteString(chr(13))) PosBeg = Pos+4 PosEnd = InstrB(PosBeg,RequestBin,boundary)-2 Value = getString(MidB(RequestBin,PosBeg,PosEnd-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 UploadRequest.Add name, UploadControl 'Loop to next object BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary) Loop End Sub
'String to byte string conversion Function getByteString(StringStr) For i = 1 to Len(StringStr) char = Mid(StringStr,i,1) getByteString = getByteString & chrB(AscB(char)) Next End Function
'Byte string to string conversion Function getString(StringBin) getString ="" For intCount = 1 to LenB(StringBin) getString = getString & chr(AscB(MidB(StringBin,intCount,1))) Next End Function
Function UploadFormRequest(name) on error resume next if UploadRequest.Item(name) then UploadFormRequest = UploadRequest.Item(name).Item("Value") end if End Function
'Process the upload UploadQueryString = Replace(Request.QueryString,"SP_upload=true","") if mid(UploadQueryString,1,1) = "&" then UploadQueryString = Mid(UploadQueryString,2) end if
If (CStr(Request.QueryString("SP_upload")) <> "") Then SP_redirectPage = "Productsupdate.asp?ProductID="&Request.QueryString("ProductID") If (SP_redirectPage = "") Then SP_redirectPage = CStr(Request.ServerVariables("URL")) end if
RequestBin = Request.BinaryRead(Request.TotalBytes) Dim UploadRequest Set UploadRequest = CreateObject("Scripting.Dictionary") BuildUploadRequest RequestBin
SP_keys = UploadRequest.Keys for SP_i = 0 to UploadRequest.Count - 1 SP_curKey = SP_keys(SP_i) 'Save all uploaded files if UploadRequest.Item(SP_curKey).Item("FileName") <> "" then SP_value = UploadRequest.Item(SP_curKey).Item("Value") SP_valueBeg = UploadRequest.Item(SP_curKey).Item("ValueBeg") SP_valueLen = UploadRequest.Item(SP_curKey).Item("ValueLen")
if SP_valueLen = 0 then Response.Write "<B>An error has occured saving uploaded file!</B><br><br>" Response.Write "Filename: " & Trim(SP_curPath) & UploadRequest.Item(SP_curKey).Item("FileName") & "<br>" Response.Write "File does not exists or is empty.<br>" Response.Write "Please correct and <A HREF=""java script:history.back(1)"">try again</a>" response.End end if
'Create a Stream instance Dim SP_strm1, SP_strm2 Set SP_strm1 = Server.CreateObject("ADODB.Stream") Set SP_strm2 = Server.CreateObject("ADODB.Stream")
'Create and Write to a File SP_curPath = "../../database/" on error resume next SP_strm2.SaveToFile Trim(Server.mappath(SP_curPath))& "/" & Request.QueryString("ProductID")&Right(UploadRequest.Item(SP_curKey).Item("FileName"),4),2 'Save the filename to the database Dim NewFilename NewFilename = Request.QueryString("ProductID")&Right(UploadRequest.Item(SP_curKey).Item("FileName"),4) set comUpdateProducts = Server.CreateObject("ADODB.Command") comUpdateProducts.ActiveConnection = MM_Cart_STRING comUpdateProducts.CommandText = "UPDATE Products SET Picture = '"& NewFilename &"' WHERE ProductID = " & Request.QueryString("ProductID") & "" comUpdateProducts.CommandType = 1 comUpdateProducts.CommandTimeout = 0 comUpdateProducts.Prepared = true comUpdateProducts.Execute()
if err then Response.Write "<B>An error has occured saving uploaded file!</B><br><br>" Response.Write "Filename: " & Trim(SP_curPath) & UploadRequest.Item(SP_curKey).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=""java script:history.back(1)"">try again</a>" err.clear Response.End end if end if next Response.Redirect(SP_redirectPage) end if %> /Mogens
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.