FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Question about binary transfers in POST requests
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Question about binary transfers in POST requests [message #172286 is a reply to message #172272] Wed, 09 February 2011 07:06 Go to previous message
Felix Saphir is currently offline  Felix Saphir
Messages: 8
Registered: December 2010
Karma:
Junior Member
Anthony Papillion <papillion(at)gmail(dot)com> wrote:
>
> I'm accessing an API that tells me I need to send the following
> information as part of a POST request:
>
> username
> password
> media
>
> Username and password are obviously passed via a url like
> &username=$username or whatever but media is confusing me. It
> needs to be the BINARY content of a media file. I'm using cURL
> to do the transfer and I suspect I'm going to use some setting
> like CURLOPT_BINARYTRANSFER but I'm not sure how to do it.

There's no need for CURLOPT_BINARYTRANSFER. The trick is to
prepend the filename with '@' like this:

$postdata = array(
'username' => $username,
'password' => $password,
'media' => "@$file['tmp_name']",
);

You then add your data to the cURL request:

curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);

It's all in the manual btw ...

Felix
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Unexpected error in log: php_gd2.dll
Next Topic: Will this work?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Sep 20 10:36:25 GMT 2024

Total time taken to generate the page: 0.07010 seconds