Hur långt har du kommit?
Lägg med textfält och hämta ut dem med UploadRequest.Item(fältnamn).Item("Value")
11 svar · 935 visningar · startad av fakenick!
denna tråd behandlar om att ladda upp flera filer samtidigt
komponentslöst...
http://www.webforum.nu/showthread.php?t=6531
ifall jag nu skulle vilja skapa en bildtext till varje uppladdad bild?
och hämta den från samma form som inputsen för bilderna... hur
går man tillväga då?
har hobbytestat litegrann, men inte kommit fram till någon vettig lösning...
tacksam för svar!
mvh john norrby
Hur långt har du kommit?
Lägg med textfält och hämta ut dem med UploadRequest.Item(fältnamn).Item("Value")
jag har absolut inte full koll på allt här, men funktionen utan bildtext fungerar iallafall... men nu till funktionen MED bildtext, berätta gärna om det finns någon onödig kod man kan ta bort.
vet t.ex. inte ifall det är nödvändigt att namnge var och ett file-fält, etc...
här är koden jag försöker med just nu iaf:
[B]comment = UploadRequest.Item("comment").Item("Value")
file01 = UploadRequest.Item("file01").Item("Value")
file02 = UploadRequest.Item("file02").Item("Value")
file03 = UploadRequest.Item("file03").Item("Value")
file04 = UploadRequest.Item("file04").Item("Value")
file05 = UploadRequest.Item("file05").Item("Value")
file06 = UploadRequest.Item("file06").Item("Value")
file07 = UploadRequest.Item("file07").Item("Value")
file08 = UploadRequest.Item("file08").Item("Value")
file09 = UploadRequest.Item("file09").Item("Value")
file10 = UploadRequest.Item("file10").Item("Value")
' ?????????[/B]
for each fobj in UploadRequest
if UploadRequest.Item(fobj).Item("FileName")<>"" then
contentType = UploadRequest.Item(fobj).Item("ContentType")
filepathname = UploadRequest.Item(fobj).Item("FileName")
filename = date &", "& time
' filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
value = UploadRequest.Item(fobj).Item("Value")
'Create FileSytemObject Component
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
'Create and Write to a File
pathEnd = Len(Server.mappath(Request.ServerVariables("PATH_INFO")))-14
' Set MyFile = ScriptObject.CreateTextFile(Left(Server.mappath(Request.ServerVariables("PATH_INFO")),pathEnd)&filename)
Set MyFile = ScriptObject.CreateTextFile(Server.mappath("img/"& filename))
end if
'response.write(Server.mappath(filename))
For i = 1 to LenB(value)
MyFile.Write chr(AscB(MidB(value,i,1)))
Next
x = x + 1
[B]comments = ""& comment &","
' ger kommentar1, kommentar2, kommentar3 etc... förhoppningsvis :)
filenames = ""& filename &","
' ger filnamn1, filnamn2, filnamn3 etc[/B]
MyFile.Close
mycket som är oklart från min sida.... :(:)
Om du vill ha en bildtext per bild så måste du ha ett textfält per bild, t.ex. comment01, comment02 etc.
vad skall man skriva för att den skall hämta upp respektive värde för comment i loopen då?
detta har jag kommit fram till..
men får felet "expected statement" på raden där 1text = text01 står:
<% Sub BuildUploadRequest(RequestBin)
'Get the boundary
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
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))
'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 = MidB(RequestBin,PosBeg,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))
End If
'Add content to dictionary object
UploadControl.Add "Value" , Value
'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
Response.Expires=0
Response.Buffer = TRUE
Response.Clear
'Response.BinaryWrite(Request.BinaryRead(Request.TotalBytes) )
byteCount = Request.TotalBytes
'Response.BinaryWrite(Request.BinaryRead(varByteCount))
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin
place = UploadRequest.Item("place").Item("Value")
thedate = UploadRequest.Item("date").Item("Value")
descr = UploadRequest.Item("descr").Item("Value")
text01 = UploadRequest.Item("text01").Item("Value")
text02 = UploadRequest.Item("text02").Item("Value")
text03 = UploadRequest.Item("text03").Item("Value")
text04 = UploadRequest.Item("text04").Item("Value")
text05 = UploadRequest.Item("text05").Item("Value")
text06 = UploadRequest.Item("text06").Item("Value")
text07 = UploadRequest.Item("text07").Item("Value")
text08 = UploadRequest.Item("text08").Item("Value")
text09 = UploadRequest.Item("text09").Item("Value")
text10 = UploadRequest.Item("text10").Item("Value")
file01 = UploadRequest.Item("file01").Item("Value")
file02 = UploadRequest.Item("file02").Item("Value")
file03 = UploadRequest.Item("file03").Item("Value")
file04 = UploadRequest.Item("file04").Item("Value")
file05 = UploadRequest.Item("file05").Item("Value")
file06 = UploadRequest.Item("file06").Item("Value")
file07 = UploadRequest.Item("file07").Item("Value")
file08 = UploadRequest.Item("file08").Item("Value")
file09 = UploadRequest.Item("file09").Item("Value")
file10 = UploadRequest.Item("file10").Item("Value")
x = 0
for each fobj in UploadRequest
if UploadRequest.Item(fobj).Item("FileName")<>"" then
contentType = UploadRequest.Item(fobj).Item("ContentType")
filepathname = UploadRequest.Item(fobj).Item("FileName")
filename = place & "" & occasion & "" & replace(time,":","") & Right(filepathname,4)
' filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
value = UploadRequest.Item(fobj).Item("Value")
'Create FileSytemObject Component
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
'Create and Write to a File
pathEnd = Len(Server.mappath(Request.ServerVariables("PATH_INFO")))-14
' Set MyFile = ScriptObject.CreateTextFile(Left(Server.mappath(Request.ServerVariables("PATH_INFO")),pathEnd)&filename)
Set MyFile = ScriptObject.CreateTextFile(Server.mappath("mgl/"& filename))
'response.write(Server.mappath(filename))
For i = 1 to LenB(value)
MyFile.Write chr(AscB(MidB(value,i,1)))
Next
x = x + 1
filenames = ""& filename &","
if x = "1" then
[B]1text = text01[/B]
elseif x = "2" then
2text = text01 &", "& text02
elseif x = "3" then
3text = text01 &", "& text02 &", "& text03
elseif x = "4" then
4text = text01 &", "& text02 &", "& text03 &", "& text04
elseif x = "5" then
5text = text01 &", "& text02 &", "& text03 &", "& text04 &", "& text05
elseif x = "6" then
6text = text01 &", "& text02 &", "& text03 &", "& text04 &", "& text05 &", "& text06
elseif x = "7" then
7text = text01 &", "& text02 &", "& text03 &", "& text04 &", "& text05 &", "& text06 &", "& text07
elseif x = "8" then
8text = text01 &", "& text02 &", "& text03 &", "& text04 &", "& text05 &", "& text06 &", "& text07 &", "& text08
elseif x = "9" then
9text = text01 &", "& text02 &", "& text03 &", "& text04 &", "& text05 &", "& text06 &", "& text07 &", "& text08 &", "& text09
elseif x = "10" then
10text = text01 &", "& text02 &", "& text03 &", "& text04 &", "& text05 &", "& text06 &", "& text07 &", "& text08 &", "& text09 &", "& text10
end if
MyFile.Close
%>
<%=1text%><br>
<%=2text%><br>
<%=3text%><br>
<%=4text%><br>
<%=5text%><br>
<%=6text%><br>
<%=7text%><br>
<%=8text%><br>
<%=9text%><br>
<%=10text%><br>
<%=place%><br>
<%=desc%><br>
<%=thedate%><br>
<% end if
next %>
Det har att göra med tillåtna variabelnamn, man får inte börja med en siffra, har jag för mig!
Jag förstår inte vad du försöker göra. Varför sätter du ihop alla textfält, med komma emellan?
Kan dessutom tipsa om http://www.freeaspupload.net/ , som är en färdigskriven klass (inte en komponent) för uppladdning.
filnamnen med komma emellan hämtar jag ut med en splitfunktion senare. :)
men jag kommer nog att lösa detta själv. skriver här igen när jag lyckats.
hej igen! :)
Nae, jag lyckas bara inte fixa detta!!
Så här vill jag att det skall fungera och
det genererar just nu detta fel:
This key is already associated with an element of this collection
/temp/multifileupload/funkah.asp, line 48
och line 48 innehåller
UploadRequest.Add name, UploadControl
varför vet jag inte...
...här kommer hela koden:
<% Sub BuildUploadRequest(RequestBin)
'Get the boundary
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
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))
'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 = MidB(RequestBin,PosBeg,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))
End If
'Add content to dictionary object
UploadControl.Add "Value" , Value
'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
Response.Expires=0
Response.Buffer = TRUE
Response.Clear
'Response.BinaryWrite(Request.BinaryRead(Request.TotalBytes) )
byteCount = Request.TotalBytes
'Response.BinaryWrite(Request.BinaryRead(varByteCount))
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin
place = UploadRequest.Item("place").Item("Value")
thedate = UploadRequest.Item("date").Item("Value")
descr = UploadRequest.Item("descr").Item("Value")
text1 = UploadRequest.Item("text01").Item("Value")
text2 = UploadRequest.Item("text02").Item("Value")
text3 = UploadRequest.Item("text03").Item("Value")
text4 = UploadRequest.Item("text04").Item("Value")
text5 = UploadRequest.Item("text05").Item("Value")
text6 = UploadRequest.Item("text06").Item("Value")
text7 = UploadRequest.Item("text07").Item("Value")
text8 = UploadRequest.Item("text08").Item("Value")
text9 = UploadRequest.Item("text09").Item("Value")
text10 = UploadRequest.Item("text10").Item("Value")
file01 = UploadRequest.Item("file01").Item("Value")
file02 = UploadRequest.Item("file02").Item("Value")
file03 = UploadRequest.Item("file03").Item("Value")
file04 = UploadRequest.Item("file04").Item("Value")
file05 = UploadRequest.Item("file05").Item("Value")
file06 = UploadRequest.Item("file06").Item("Value")
file07 = UploadRequest.Item("file07").Item("Value")
file08 = UploadRequest.Item("file08").Item("Value")
file09 = UploadRequest.Item("file09").Item("Value")
file10 = UploadRequest.Item("file10").Item("Value")
x = 0
for each fobj in UploadRequest
if UploadRequest.Item(fobj).Item("FileName")<>"" then
contentType = UploadRequest.Item(fobj).Item("ContentType")
filepathname = UploadRequest.Item(fobj).Item("FileName")
filename = place & "" & thedate & "" & replace(time,":","") & Right(filepathname,4)
' filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
value = UploadRequest.Item(fobj).Item("Value")
'Create FileSytemObject Component
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
'Create and Write to a File
pathEnd = Len(Server.mappath(Request.ServerVariables("PATH_INFO")))-14
' Set MyFile = ScriptObject.CreateTextFile(Left(Server.mappath(Request.ServerVariables("PATH_INFO")),pathEnd)&filename)
Set MyFile = ScriptObject.CreateTextFile(Server.mappath("tezt/"& filename))
'response.write(Server.mappath(filename))
For i = 1 to LenB(value)
MyFile.Write chr(AscB(MidB(value,i,1)))
Next
x = x + 1
MyFile.Close
end if %>
<%=filename%><br>
<%=text & x%><br>
<%=place%><br>
<%=thedate%><br>
<%=descr%><br>
<% next %>
Jag vill alltså här loopa ut för varje fil ett
filnamn, en kommentar, ett ställe, ett datum och en
beskrivning som jag senare kan spara i en databas!
Jag vet iallafall att jag har själva formuläret rätt..
enctype multipart etc..
Någon som vet orsaken till detta problem och vet en utväg?
Mvh John Norrby
Det felmeddelandet säger är att ditt Dictionary redan har en nyckel med det namn du försöker adda, så när du kör ditt script måste du vara helt säker på att en nyckel aldrig kommer att förekomma två gånger.
Om denna rad genererar samma namn två (eller fler) gånger:
Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
så kommer denna rad mycket riktigt att slå bakut:
UploadRequest.Add name, UploadControl
Prova med att skriva ut vilka Name du får och se om det är uppenbart varför det klagar. :)
/Jonas
Hm, okej. Jag ska testa.
Men det som är mysko är att scriptet fungerar alldeles utmärkt
sålänge man inte har fler värden med. scriptet med att ladda upp
flera bilder på en o samma gång fungerar bra, men när jag vill ha
in bildtext och lite annan trevlig information så vill det inte riktigt
fungera. :(