-
-
Save johntitus/3907209 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' => "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; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I updated the original code after alixaxel informed me about jQuery sending the object in the POST variable
images
rather thandata
. However, I still cannot get my test to work (as mentioned in my answer)... So you should pull the changes from the original.