cURL and HTTP file uploads

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

cURL and HTTP file uploads

Post 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.
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: cURL and HTTP file uploads

Post by php_east »

miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Re: cURL and HTTP file uploads

Post 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.
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: cURL and HTTP file uploads

Post 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.
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Re: cURL and HTTP file uploads

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: cURL and HTTP file uploads

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: cURL and HTTP file uploads

Post 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.
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Re: cURL and HTTP file uploads

Post 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.
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: cURL and HTTP file uploads

Post by php_east »

and thanks for the confirmation.
Post Reply