####################################
Pour ça, tu copies les 3 fonctions suivantes dans un fichier genre 'uploadfunction.inc'
<%
REM *** Isole le nom du fichier du chemin complet ***
Function GetFileName(FullPath)
Dim Pos, PosF
PosF = 0
For Pos = Len(FullPath) To 1 Step -1
Select Case Mid(FullPath, Pos, 1)
Case "/", "\": PosF = Pos + 1: Pos = 0
End Select
Next
If PosF = 0 Then PosF = 1
GetFileName = Mid(FullPath, PosF)
End Function
REM *** Convertie une chaine UTF en unicode (abus de language) ***
Function getString(StringBin)
getString =""
For intCount = 1 To LenB(StringBin)
getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
Next
End Function
REM *** Réciproque de la fonction d'avant ***
Function getByteString(StringStr)
For i = 1 To Len(StringStr)
char = Mid(StringStr, i, 1)
getByteString = getByteString & chrB(AscB(char))
Next
End Function
REM *** Construit l'objet Scripting.Dictionnary intégrant l'ensemble des éléments du form ***
Function BuildUploadRequest(RequestBin)
Dim scrDict
Set scrDict = Server.CreateObject("Scripting.Dictionary"
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
scrDict.Add Name, UploadControl
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
Loop
Set BuildUploadRequest = scrDict
Set scrDict = Nothing
End Function
%>
###########################
Enfin tu récupères les éléments du POST en faisant :
<%str = Dict.Item("formfield-name".Item("Value"%>
' Pour enregistrer le fichier dans un répertoire :
Set fichierconn = Server.CreateObject("Scripting.FileSystemObject"
Set file = fichierconn.CreateTextFile("c:\tmp\" & GetFileName(Dict.Item("fichier".Item("FileName"))
file.write(getString(Dict.Item("fichier".Item("Value"))
file.close
Set file = nothing
Set fichierconn = nothing
##################
Voila !!!!
Bon, normalement pour que tout marche bien, il faut tester les erreurs et tout ça... En plus, pour les gros fichiers (>75Ko), il faudrait que tu fractionnes le flux "binData" en plusieurs morceaux parce qu'avec tout les appels de fonctions le serveur IIS se met à ramer terriblement (trop de transfert de données). Et si t'as un probleme, tu peux m'écrire à anqh@yahoo.com
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.