joadha
joadha

Reputation: 191

How does one POST a binary file stored locally using php-curl?

I wish to issue the following curl request using php-curl:

curl "http://www.example.com/" -F "[email protected]"

How do I need to set this up in PHP (using curl_init, _setopt, etc.), assuming foo.ext lives on the machine from which I'm issuing the request?

Upvotes: 3

Views: 2969

Answers (1)

Marc B
Marc B

Reputation: 360632

you'd use

curl_setopt($curl_handle, CURLOPT_POST, TRUE);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, array('file' => '@foo.ext'));

plus whatever options you need. Relevant docs here: http://php.net/curl_setopt

Upvotes: 5

Related Questions