ça marche tres bien avec les fichiers text mais pas avec les images quelqu'un a une idée ?
Code : Tout sélectionner
Structure ProxyStructure
Adr.s
Port.l
login.s
password.s
EndStructure
Global Proxy.ProxyStructure
Structure FileStructure
Name.s
Size.l
Type.b
EndStructure
Global Dim File.FileStructure(100),NbFile,Folder.s,AddPath.s
;-Paramètre
Proxy\Adr=""
Proxy\Port=80
Proxy\login=""
Proxy\password=""
Folder="http://yann.lebrun.club.fr/temps/" ;Repertoire de base
AddPath=""; si jamais on navigue dans le repertoire de base
;- Window Constants
Enumeration
#Main
EndEnumeration
;- Gadget Constants
;
Enumeration
#ExplorerList
EndEnumeration
InitNetwork()
;-Download
Procedure.s MyDownload(Url.s,UseProxy=#False)
Protected Server.s,Port.l,conc$,enc$,Header.s,Res.l,*Buffer = AllocateMemory(1024),String.s,DataLength.l
;Si j'ai un Proxy je dois me connecter au Proxy
If UseProxy=#True
Path.s=Url
Server.s=Proxy\Adr
Port.l=Proxy\Port
conc$=Proxy\login+":"+Proxy\password
OutputBuffer = AllocateMemory(Len(conc$)*4)
Base64Encoder(@conc$,Len(conc$),OutputBuffer,Len(conc$)*4)
enc$=PeekS(OutputBuffer)
;Si je n'ai pas de proxy on se connecte directement au serveur
ElseIf UseProxy=#False
Port=80
Path.s = Url
Url.s = RemoveString(Url,"http://",1)
i = FindString(Url,"/",1)
If i
Server = Left(Url,i-1)
Else
Server = Url
EndIf
EndIf
;Connection au Serveur
ConnectionID = OpenNetworkConnection(Server, Port)
If ConnectionID
;Creation de l'entête a envoyer
Header ="GET "+Path+" HTTP/1.1"+#CRLF$
If UseProxy=#True
Header + "Proxy-Authorization: Basic "+enc$+#CRLF$
Else
Header + "Host: "+Server+#CRLF$+#CRLF$
EndIf
Header+#CRLF$
Res=SendNetworkData(ConnectionID,@Header,Len(Header))
Delay(10)
result = NetworkClientEvent(ConnectionID)
Repeat ;On lit les données qui arrive
DataLength = ReceiveNetworkData(ConnectionID,*Buffer,1024)
String + PeekS(*Buffer,DataLength)
Until DataLength<1024
FreeMemory(*Buffer) ;POuff! Pu besoin on efface
MessageRequester("Done!","Your Data" + Chr(13) + Chr(10) + Trim(String),0)
;C'est finit on se deconnecte
CloseNetworkConnection(ConnectionID)
debut = FindString(String, #CRLF$+#CRLF$, 1)
String = Right(String, Len(String) - debut - 3)
ProcedureReturn String
EndIf
EndProcedure
;-Upload
Procedure Upload(File.s)
;################################################################
;# 22/2/2006 - Upload file to web trough POST command | Pantcho #
;################################################################
URL$ = "127.0.0.1" ; the main domain
PATH$ = "/CgiFileIn.Php" ; or what ever script that accepts the enctype="multipart/form-data"
FullFileName$ = "c:\pb\text.txt" ; Full path+filename
ActionName$ = "file" ; this is important!! this action must be the same as <form ... name="file">
FileHeader$ = "Content-Disposition: form-Data; name="+Chr(34)+ActionName$ + Chr(34) +"; filename="+Chr(34)+ FullFileName$+ Chr(34) +#CRLF$
FileHeader$ + "Content-Type: text/plain" ; <= Here change the content type regarding your file! (text,image etc...) we go on text
; ^^^ note: Havn't been tested with binary files.
Border$ = "23232323232" ; Border to the file data (Check RFC for more info)
If InitNetwork()
conid.l = OpenNetworkConnection(URL$,80)
If conid
Debug "Connected"
*Buffer = AllocateMemory(100000) ; some memory for our file buffer
POST$ = "POST "+ PATH$ +" HTTP/1.0" ; the Post command we are going to send to the server
OpenFile(1,FullFileName$)
Repeat
Text$ = ReadString(1)
FILE$ + Chr(13) + Chr(10)+Text$
Until Eof(1)
; This is the border header for uploading
FILE$ = "------"+Border$ + #CRLF$ + FileHeader$ +#CRLF$ + FILE$ + "------" + Border$ + "--"
; Back to post, while sending header with the correct content length (border+file+border)
POST$ + #CRLF$ + "Content-Type: multipart/form-Data, boundary=----"+Border$ + #CRLF$ + "Content-Length: " + Str(Len(FILE$))
POST$ + #CRLF$ + #CRLF$ + FILE$
CloseFile(1)
PokeS(*Buffer,"",0)
PokeS(*Buffer,POST$,Len(POST$))
SendNetworkData(conid,*Buffer,Len(POST$))
Repeat
Server$ = PeekS(*Buffer)
Debug Server$
res.l = ReceiveNetworkData(conid, *Buffer, 1000)
Until Server$ = PeekS(*Buffer)
Else
Debug "NO CONNECTION"
EndIf
EndIf
EndProcedure
;-Procedure pour le Drag 'N Drop
Procedure.l DropFiles()
ProcedureReturn EventwParam()
EndProcedure
Procedure GetNumDropFiles(*dropFiles)
ProcedureReturn DragQueryFile_(*dropFiles, $FFFFFFFF, temp$, 0)
EndProcedure
Procedure.s GetDropFile(*dropFiles, index)
bufferNeeded = DragQueryFile_(*dropFiles, index, 0, 0)
For a = 1 To bufferNeeded: buffer$ + " ": Next ; Short by one character!
DragQueryFile_(*dropFiles, index, buffer$, bufferNeeded+1)
ProcedureReturn buffer$
EndProcedure
Procedure FreeDropFiles(*dropFiles)
DragFinish_(*dropFiles)
EndProcedure
;-Examine File
Procedure ExamineFile()
Url.s=Folder+"File.php?path="+AddPath
Debug url
Directory.s=MyDownload(Url)
P_Start=FindString(Directory,"<Thyphoon>",0)
P_End=FindString(Directory,"</Thyphoon>",0)
Directory.s=ReplaceString(Mid(Directory,P_Start,P_End-P_Start),"<Thyphoon>","")
NbFile = CountString(Directory,Chr(10))
For a=1 To NbFile
Ligne.s=StringField(Directory,a,Chr(10))
Debug Ligne
File(a)\Name=StringField(Ligne,1,",")
Select StringField(Ligne,3,",")
Case "dir"
File(a)\Type=#PB_DirectoryEntry_Directory
Case "file"
File(a)\Type=#PB_DirectoryEntry_File
EndSelect
File(a)\Size=Val(StringField(Ligne,2,","))
Next
EndProcedure
; Procedure ExamineFile()
; Directory$ = "Temps\" ; Énumère le contenu du répertoire C (Les sous-répertoires ne sont pas examinés)
; If ExamineDirectory(0, Directory$, "*.*")
; While NextDirectoryEntry(0)
; If DirectoryEntryType(0) = #PB_DirectoryEntry_File Or DirectoryEntryType(0) = #PB_DirectoryEntry_Directory
; NbFile+1
;
; File(NbFile)\Name=DirectoryEntryName(0)
; File(NbFile)\Type=DirectoryEntryType(0)
; File(NbFile)\Size=DirectoryEntrySize(0)
; Debug File(NbFile)\Name
; EndIf
; Wend
; FinishDirectory(0)
; EndIf
;
; EndProcedure
Procedure UpdateExlorerlist()
ClearGadgetItemList(#ExplorerList)
For z=1 To NbFile
AddGadgetItem(#ExplorerList,-1,File(z)\Name+Chr(10)+Str(File(z)\Size)+" Ko")
Next
EndProcedure
Procedure Open_Window_0()
If OpenWindow(#Main, 0, 0, 668, 300, "Synchro", #PB_Window_ScreenCentered| #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
DragAcceptFiles_(WindowID(#Main), 1)
If CreateGadgetList(WindowID(#Main))
ListIconGadget(#ExplorerList, 0, 0, 350, 65, "", 200,#PB_ListIcon_GridLines)
AddGadgetColumn(#ExplorerList, 0, "Name ", 65)
AddGadgetColumn(#ExplorerList, 1, "Size ", 65)
AddGadgetColumn(#ExplorerList, 2, "Type ", 65)
AddGadgetColumn(#ExplorerList, 3, "Modified ", 65)
EndIf
EndIf
EndProcedure
Procedure RunFile(n.l)
url.s=Folder+AddPath+File(n)\Name
Debug "Download..."+url
String.s=MyDownload(url,#False)
If CreateFile(0,GetFilePart(Url))
WriteData(0,@String,Len(String))
CloseFile(0)
EndIf
Date_Before=GetFileDate(GetFilePart(Url), #PB_Date_Modified)
RunProgram(GetFilePart(Url),"", "", #PB_Program_Wait)
Date_After=GetFileDate(GetFilePart(Url), #PB_Date_Modified)
If Date_Before<>Date_After
Debug "on Upload le fichier"
Else
Debug "pas besoin d'uploader"
EndIf
EndProcedure
Open_Window_0()
ExamineFile()
UpdateExlorerlist()
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_SizeWindow
ResizeGadget(#ExplorerList, 0, 0, WindowWidth(#Main), WindowHeight(#Main))
Case #WM_DROPFILES
*dropped = DropFiles()
num.l = GetNumDropFiles(*dropped)
f$ = ""
For files = 0 To num - 1
f$ + GetDropFile(*dropped, files) + Chr (13)
Next
MessageRequester("Drag 'n' Drop", Str (num) + " file (s) dropped:" + Chr (13) + Chr (13) + f$)
FreeDropFiles(*dropped)
Case #PB_Event_Gadget
Select EventGadget()
Case #ExplorerList
Select EventType()
Case #PB_EventType_LeftDoubleClick
;On selectionne le fichier qu'on veut charger
f=GetGadgetState(#ExplorerList)+1
;Si on a un fichier
If f>0 And File(f)\Type=#PB_DirectoryEntry_File
Debug "chargement du fichier"
Thread = CreateThread(@RunFile(), f)
;Si on a un repertoir
ElseIf f>0 And File(f)\Type=#PB_DirectoryEntry_Directory
Debug "changement de repertoir"
;Si on doit retourner en arrière dans le chemin
If File(f)\Name=".."
;Sinon on rajoute le chemin
Else
AddPath+File(f)\Name+"/"
ExamineFile()
UpdateExlorerlist()
EndIf
EndIf
;
EndSelect
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow