Skip to content

Instantly share code, notes, and snippets.

@bugsysailor
Forked from jacktasia/imgix_purge.php
Last active April 26, 2016 00:02
Show Gist options
  • Save bugsysailor/84201b2bc4fecf2e3a047a2f7944cafb to your computer and use it in GitHub Desktop.
Save bugsysailor/84201b2bc4fecf2e3a047a2f7944cafb to your computer and use it in GitHub Desktop.
imgix PHP purge example
<?php
// pass the url you want to purge
function imgix_purge($url, $apikey = '') {
$headers = array(
'Content-Type:application/json',
'Authorization: Basic '. base64_encode($apikey.':')
);
$payload = json_encode(array("url" => $url));
$curl = curl_init('https://api.imgix.com/v2/image/purger');
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
// usage
$imgix_url = 'http://yourcompany.imgix.net/examples/mountain.jpg';
echo imgix_purge($imgix_url);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment