Skip to content

Instantly share code, notes, and snippets.

@notslang
Created October 17, 2012 14:36
Show Gist options
  • Save notslang/3905855 to your computer and use it in GitHub Desktop.
Save notslang/3905855 to your computer and use it in GitHub Desktop.
ZipPlease PHP API example
<?php
//this file would be at /demo/flickr.php
$zipPleaseAPIEndpoint = "http://www.zipplease.com/api/zips";
$uniqueZipName = "zipPleaseFlickrDemo_" . uniqid() . ".zip";
// Create the JSON payloy to send to ZipPlease
$zipRequest = json_encode(array(
'accountKey' => "6B5qClA0SG2er7x7PmZTK4QU", // Not real.
'accountSecret' => "jHxRb2y3CevJyROL96hYKcE0oAIQ", // Get your own.
'zipName' => $uniqueZipName,
'files' => $_POST['images'], // Incoming request from the front end
'compress' => false // already jpegs
));
$params = array(
'http' => array(
'method' => 'POST',
'content' => $zipRequest
)
);
// Send the request to ZipPlease.
$fp = @fopen($zipPleaseAPIEndpoint, 'rb', false, stream_context_create($params));
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
// The response includes a URL where the Zip can be downloaded.
// We'll send that URL back to the front end.
header('Content-Type: application/json');
die($response);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment