Follow

Sample for upload logo for the offer PHP [API]

Here is the example of request to upload the logo to the offer. 
!!!Requirements: (PHP 5 >= 5.5.0, PHP 7)!!!

<?php
//Requirements: (PHP 5 >= 5.5.0, PHP 7)
$url = 'http://api.{instance}.affise.com/2.1/admin/offer/{id}';
$apiKey = 'API_KEY';
$filePath = 'example.png';
if (version_compare(PHP_VERSION, '5.5.0') < 0) {
throw new Exception("You are using the old PHP version. Need at least 5.5.0. You version: " . PHP_VERSION);
}
if (!file_exists($filePath)) {
throw new Exception("File '{$filePath}' not exists");
};
$ch = curl_init($url);
$cfile = new CURLFile($filePath, filetype($filePath), basename($filePath));
// Assign POST data
$data = [
'logo' => $cfile
];
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: multipart/form-data',
'Api-Key: ' . $apiKey
));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute the handle
curl_exec($ch);
if (curl_exec($ch) === false) {
throw new Exception("Curl error: " . curl_error($ch));
} else {
echo "Uploaded successfully!\n";
}
// close the session
curl_close($ch);


Was this article helpful?
1 out of 1 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.