Page 1 of 1

cURL and HTTP file uploads

Posted: Thu Mar 05, 2009 11:28 am
by miro_igov
Is that possible? I had to read a lot about cURL and file uploads and i am starting to convince that file uploads through HTTP is not possible :banghead:

The goal is to submit a multipart/form-data form to a server but with cURL.

Re: cURL and HTTP file uploads

Posted: Thu Mar 05, 2009 12:32 pm
by php_east

Re: cURL and HTTP file uploads

Posted: Thu Mar 05, 2009 1:16 pm
by miro_igov
Can you confirm that http file upload works? I seen the code and i doubt it works, but will test it tomorrow.

Re: cURL and HTTP file uploads

Posted: Thu Mar 05, 2009 1:52 pm
by php_east
no, personally i cannot as i have not used it myself, but the examples are done by cURL developers. surely they know what they are doing ? the site is cURL library developer site. if you doubt them, i don't know where or who else can be a better reference. that there is the factory.

wether you use the info there is up to you, but i know they have gone as far as cURL proxy. yum yum :P

do read up on the examples. there is trick involved where the post need to go to the cURL routine itself first in order for the file contents to get posted. and then that will be sent to remote, otherwise blank. this was reported by one of them in the examples.

Re: cURL and HTTP file uploads

Posted: Thu Mar 05, 2009 2:29 pm
by miro_igov
Actually i am trying to upload local file at server 1 to server 2, as i see they set the filename as variable and then use the key=>@filename as post param. the @ operator suppress notices and warnings as i know, no clue why it is used here. Will test it tomorrow, practice shows that things should not be accepted as truth when coming out from the kitchen.

Re: cURL and HTTP file uploads

Posted: Thu Mar 05, 2009 4:10 pm
by VladSun
CURLOPT_POSTFIELDS

The full data to post in a HTTP "POST" operation. To post a file, prepend a filename with @ and use the full path. This can either be passed as a urlencoded string like 'para1=val1&para2=val2&...' or as an array with the field name as key and field data as value.

Re: cURL and HTTP file uploads

Posted: Thu Mar 05, 2009 4:22 pm
by php_east
miro_igov wrote:Actually i am trying to upload local file at server 1 to server 2, as i see they set the filename as variable and then use the key=>@filename as post param. the @ operator suppress notices and warnings as i know, no clue why it is used here. Will test it tomorrow, practice shows that things should not be accepted as truth when coming out from the kitchen.
in the context of PHP core yes, but this is a library, and the library has its own way to handle the @'s obviously, quite separate from the core.

Re: cURL and HTTP file uploads

Posted: Fri Mar 06, 2009 6:50 am
by miro_igov
Ok i can confirm that it works. Many thanks!! The example at curl.haxx.se had syntax error but the idea works at all.

Re: cURL and HTTP file uploads

Posted: Fri Mar 06, 2009 7:36 pm
by php_east
and thanks for the confirmation.