error_reporting(E_ALL); require_once 'sdk.class.php'; require_once 'include/book.inc.php'; // Make sure that the right number of arguments were supplied if ($argc != 3) { exit("Usage: " . $argv[0] . "in-bucket out-bucket\n"); } // Get arguments $bucketIn = $argv[1] == '-' ? BOOK_BUCKET : $argv[1]; $bucketOut = $argv[2] == '-' ? $bucketIn . THUMB_BUCKET_SUFFIX : $argv[2]; // Confirm intent print "Thumbnailing '{$bucketIn}' to '{$bucketOut}'\n"; // Create the S3 access object $s3 = new AmazonS3(); // Get object list from input bucket $objectsIn = getBucketObjects($s3, $bucketIn); // Process each object. Generate thumbnails only for images foreach ($objectsIn as $objectIn) { $key = $objectIn->Key; print "Processing item '{$key}':\n"; if (substr(guessType($key), 0, 6) == "image/") { $startTime = microtime(true); $dataIn = $s3->get_object($bucketIn, $key); $endTime = microtime(true); $contentType = guessType($key); printf("\tDownloaded from S3 in %.2f seconds.\n", $endTime - $startTime); $startTime = microtime(true); $dataOut = thumbnailImage($dataIn->body, $contentType); $endTime = microtime(true); printf("\tGenerated thumbnail in %.2f seconds.\n", $endTime - $startTime); $startTime = microtime(true);
* * or in the "license.txt" file accompanying this file. This file is * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS * OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the * License. * * Modified by Jeffrey S. Haemer <*****@*****.**> */ error_reporting(E_ALL); require_once 'AWSSDKforPHP/sdk.class.php'; require_once 'include/book.inc.php'; // Get parameters $bucket = isset($_GET['bucket']) ? $_GET['bucket'] : BOOK_BUCKET; // Set up page title // Create the S3 access object $s3 = new AmazonS3(); // Get list of all objects in bucket $objects = getBucketObjects($s3, $bucket); $fileList = array(); foreach ($objects as $object) { $key = $object->Key; $url = $s3->get_object_url($bucket, $key, "60 seconds"); $fileList[] = array('url' => $url, 'name' => $key, 'size' => number_format((int) $object->Size)); } // create a page header and an explanatory message $output_title = "Chapter 4 Sample - List of S3 Objects in Bucket '{$bucket}'"; $output_message = "A simple HTML table displaying of all the objects in the '{$bucket}' bucket."; // Output the HTML include 'include/list_bucket_objects.html.php'; exit(0);
require_once 'AWSSDKforPHP/sdk.class.php'; require_once 'include/book.inc.php'; // Get parameters $bucket = isset($_GET['bucket']) ? $_GET['bucket'] : BOOK_BUCKET; // Set name of bucket for thumbnails $bucketThumbs = $bucket . THUMB_BUCKET_SUFFIX; // Create the S3 and CloudFront access objects $s3 = new AmazonS3(); $cf = new AmazonCloudFront(); // Find distributions for the two buckets $dist = findDistributionForBucket($cf, $bucket); $thumbsDist = findDistributionForBucket($cf, $bucketThumbs); // Get list of all objects in main bucket $objects = getBucketObjects($s3, $bucket); // Get list of all objects in thumbnail bucket $objectThumbs = getBucketObjects($s3, $bucketThumbs); /* * Create associative array of available thumbnails, * mapping object key to thumbnail URL (either S3 * or CloudFront). */ $thumbs = array(); foreach ($objectThumbs as $objectThumb) { $key = (string) $objectThumb->Key; if ($thumbsDist != null) { $thumbs[$key] = 'http://' . $thumbsDist->DomainName . "/" . $key; } else { $thumbs[$key] = $s3->get_object_url($bucketThumbs, $key, "60 seconds"); } } $fileList = array();