-4

I've got this code in cURL. I'd like to transform or execute it in PHP.

curl -X POST -H "auth_id: {{market_id}}" -H "auth_token: {{auth_token}}" -H "Content-Type: multipart/form-data;" -F "campaign_slug={{campaign_slug}}" -F "csv=@{{file.csv}}" 'https://{{market_subdomain}}.co-buying.com/api/potential_campaign_signups/upload'

Could you please tell me how to do it ?

Thank you Bastien

Bastien
  • 35
  • 4

2 Answers2

-1

You can use curl-to-php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://{{market_subdomain}}.co-buying.com/api/potential_campaign_signups/upload");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = "Auth_id: {{market_id}}";
$headers[] = "Auth_token: {{auth_token}}";
$headers[] = "Content-Type: multipart/form-data;";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
parik
  • 2,313
  • 12
  • 39
  • 67
-2

You can use some online converters. Like https://incarnate.github.io/curl-to-php/ To write by yourself this url might a guide for you; http://code.stephenmorley.org/php/sending-files-using-curl/

also please check for full curl parameters coverage

if you can't success, you might want to try

exec($curlCommand,$result);

Also please read exec documentation

siniradam
  • 2,727
  • 26
  • 37
  • Thank you but I've already tried. And it does not take in consideration all the information like the csv file for the post. – Bastien Sep 14 '17 at 14:03
  • then please check this one out: https://stackoverflow.com/questions/1939609/convert-command-line-curl-to-php-curl – siniradam Sep 14 '17 at 14:04