Created
October 17, 2012 14:36
-
-
Save notslang/3905855 to your computer and use it in GitHub Desktop.
ZipPlease PHP API example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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