Skip to content

Instantly share code, notes, and snippets.

@johntitus
Forked from notslang/gist:3905855
Created October 17, 2012 18:28
Show Gist options
  • Save johntitus/3907209 to your computer and use it in GitHub Desktop.
Save johntitus/3907209 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' => "jHxRb2y3CevJyROL96hYKcE0oAI", // Get your own.
'zipName' => $uniqueZipName,
'files' => $_POST['data'], // Incoming request from the front end
'compress' => false // already jpegs
));
$params = array(
'http' => array(
'method' => 'POST',
'content' => $zipRequest
)
);
// Send the request to ZipPlease.
$ctx = stream_context_create($params);
$fp = @fopen($zipPleaseAPIEndpoint, 'rb', false, $ctx);
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.
return $response;
?>
@notslang
Copy link

I updated the original code after alixaxel informed me about jQuery sending the object in the POST variable images rather than data. However, I still cannot get my test to work (as mentioned in my answer)... So you should pull the changes from the original.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment