J'ai retrouvé ce vieux code de Pantcho et datant de 2006.
Il fonctionne très bien pour envoyer un fichier text, mais pour envoyer une image ça ne marche pas.
Est-ce que parmis vous quelqu'un aurait une idée comment faire ?
mon but etant au final est de pouvoir envoyer un peu n'importe quoi a un formulaire en Post ! Variable/Fichier
edit: et je precise que je veux eviter de passer part des trucs un peu lourd a mon gout comme libcurl
Code : Tout sélectionner
;SRC = http://www.purebasic.fr/english/viewtopic.php?f=13&t=19714&hilit=Upload+file+to+web+trough+POST+command
;################################################################
;# 22/2/2006 - Upload file to web trough POST command | Pantcho #
;################################################################
URL$ = "127.0.0.1" ; the main domain
PATH$ = "/test.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) +#LFCR$
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)
;RFC ????? Thyphoon :http://www.faqs.org/rfcs/rfc2616.html ???????? or http://www.iprelax.fr/http/1945tm.php
FullFileName$=OpenFileRequester("Please choose file to load", "", "*.*", 0)
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
If 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$ + #LFCR$ + FileHeader$ +#LFCR$ + FILE$ + "------" + Border$ + "--"
; Back to post, while sending header with the correct content length (border+file+border)
POST$ + #LFCR$ + "Content-Type: multipart/form-Data, boundary=----"+Border$ + #LFCR$ + "Content-Length: " + Str(Len(FILE$))
POST$ + #LFCR$ + #LFCR$ + FILE$
CloseFile(1)
PokeS(*Buffer,"",0)
PokeS(*Buffer,POST$,Len(POST$))
SendNetworkData(conid,*Buffer,Len(POST$))
If CreateFile(0,"back.txt")
Repeat
Server$ = PeekS(*Buffer)
WriteString(0,Server$)
res.l = ReceiveNetworkData(conid, *Buffer, 1000)
Until Server$ = PeekS(*Buffer)
CloseFile(0)
EndIf
Else
Debug "Can't Open File"
EndIf
Else
Debug "NO CONNECTION"
EndIf
EndIf