Wednesday, 21 August 2013

Send binary data via POST methos in cURL

Send binary data via POST methos in cURL

I am writing a script. I want to upload a pdf file with cURL. But I get
the error message in browser "PDF document didn't upload."
<?php
$service_url = "http://sample";
$curl = curl_init($service_url);
$filename = "foo.pdf";
$curl_post_data = array("fname" => "nabukkad", "lname" => "nezzar",
"email" => "n@n.com", "phone" => "05050505", "file" => "@" .
realpath($filename));
curl_setopt($curl, CURLOPT_URL, $service_url);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
$curl_response = curl_exec($curl);
header("Content-Transfer-Encoding: UTF-8");
header("Content-Type: application/pdf");
echo $curl_response;
?>

No comments:

Post a Comment