Reputation: 11
I'm pretty new to PHP so any help would be greatly appreciated.
This is running on WAMP server with cURL enabled and is supposed to upload tracking for orders i'm trying to process. But when i run this script i don't get a response so i assume its broken somewhere however i don't get any errors so i'm unsure as to whats actually happening.
The problem seems to be cause but either the way I’m creating the $datatopost array or with the actual cURL part of my code I think.
if($_REQUEST)
{
$supplier = $_REQUEST["supplier_ID"];
$token = $_REQUEST["token"];
$filePath = $_REQUEST["filePath"];
$fileName = $_REQUEST["fileName"];
}
$itemID = array();
$array = file($filePath.$fileName);
foreach($array as $value)
{
$temp = explode(",",$value);
$itemID[] = array( "carrier" => $temp[1], "ci_lineitem_id" => $temp[0], "tracking" => $temp[2]);
}
$datatopost = array (
"supplier_id" => $supplier,
"token" => $token,
"tracking_info" =>json_encode($itemID)
);
$ch = curl_init ("https://scm.commerceinterface.com/api/v2/tracking_notification");
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec ($ch);
if( $response )
{
$response_json = json_decode( $response );
if( $response_json['success'] == true )
{
file_put_contents($filePath."Success.txt", $response);
}
else
{
file_put_contents($filePath."Failed.txt", $response);
}
}
Upvotes: 1
Views: 287
Reputation: 21
You are trying to get a SSL secured site, so take a look at the CURLOPT_SSL_* options: http://php.net/manual/en/function.curl-setopt.php.
For detailed information, you should check the cURL result (like already mentioned).
Upvotes: 0
Reputation: 170
file_put_contents($filePath."Success.txt", $responce);
file_put_contents($filePath."Failed.txt", $responce);
I think the variable $responce in the file_put_contents() method is unknown. Try to use $response.
Upvotes: 1