jim smith
jim smith

Reputation: 2454

PHP curl equivelant

How can I post this in PHP?

curl -i -H "Content-Type: text/csv" -X POST --data-binary @test.csv blah/_/csvImport

This is what I have so far

$url = "http://blah/_/csvImport";
$file = "test.csv";

$request = curl_init();
// send a file
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_URL, $url);
curl_setopt($request, CURLOPT_HTTPHEADER, array("Content-Type: text/csv"));
curl_setopt(
    $request,
    CURLOPT_POSTFIELDS,
    array(
      'data' => '@' . realpath($file)
    ));


curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
echo curl_exec($request);

// close the session
curl_close($request);

Upvotes: 0

Views: 69

Answers (1)

Srijith Vijayamohan
Srijith Vijayamohan

Reputation: 915

This is the missing option:

curl_setopt($request, CURLOPT_BINARYTRANSFER, true);

CURLOPT_BINARYTRANSFER is for -data-binary

Upvotes: 1

Related Questions