Skip to content

Commit

Permalink
Updated examples, renamed enableBucketLogging to setBucketLogging
Browse files Browse the repository at this point in the history
  • Loading branch information
tpyo committed May 4, 2008
1 parent 1577652 commit 0154802
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
10 changes: 5 additions & 5 deletions S3.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,14 @@ public static function getObjectInfo($bucket = '', $uri = '', $returnInfo = true


/**
* Enable logging for buckets
* Set logging for buckets
*
* @param string $bucket Bucket name
* @param string $targetBucket Target bucket (where logs are stored)
* @param string $targetPrefix Log prefix (e,g; domain.com-)
* @return boolean
*/
public static function enableBucketLogging($bucket, $targetBucket, $targetPrefix) {
public static function setBucketLogging($bucket, $targetBucket, $targetPrefix) {
$dom = new DOMDocument;
$bucketLoggingStatus = $dom->createElement('BucketLoggingStatus');
$bucketLoggingStatus->setAttribute('xmlns', 'http://s3.amazonaws.com/doc/2006-03-01/');
Expand All @@ -433,7 +433,7 @@ public static function enableBucketLogging($bucket, $targetBucket, $targetPrefix
if ($rest->error === false && $rest->code !== 200)
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
if ($rest->error !== false) {
trigger_error(sprintf("S3::enableBucketLogging({$bucket}, {$uri}): [%s] %s",
trigger_error(sprintf("S3::setBucketLogging({$bucket}, {$uri}): [%s] %s",
$rest->error['code'], $rest->error['message']), E_USER_WARNING);
return false;
}
Expand All @@ -450,14 +450,14 @@ public static function enableBucketLogging($bucket, $targetBucket, $targetPrefix
* @param string $bucket Bucket name
* @return array | false
*/
public static function getBucketLoggingStatus($bucket = '') {
public static function getBucketLogging($bucket = '') {
$rest = new S3Request('GET', $bucket, '');
$rest->setParameter('logging', null);
$rest = $rest->getResponse();
if ($rest->error === false && $rest->code !== 200)
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
if ($rest->error !== false) {
trigger_error(sprintf("S3::getBucketLoggingStatus({$bucket}): [%s] %s",
trigger_error(sprintf("S3::getBucketLogging({$bucket}): [%s] %s",
$rest->error['code'], $rest->error['message']), E_USER_WARNING);
return false;
}
Expand Down
4 changes: 1 addition & 3 deletions example-wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
* Note: Although this wrapper works, it would be more efficient to use S3 class instead
*/

//require_once 'auth-constants.php';
require_once 'S3.php';

if (!class_exists('S3')) require_once 'S3.php';

// AWS access info
if (!defined('awsAccessKey')) define('awsAccessKey', 'change-this');
Expand Down
38 changes: 30 additions & 8 deletions example.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
* S3 class usage
*/

//require_once 'auth-constants.php';
require_once 'S3.php';

if (!class_exists('S3')) require_once 'S3.php';

// AWS access info
if (!defined('awsAccessKey')) define('awsAccessKey', 'change-this');
if (!defined('awsSecretKey')) define('awsSecretKey', 'change-this');

$uploadFile = 'S3.php'; // File to upload, we'll use the S3 class since it exists
$uploadFile = dirname(__FILE__).'/S3.php'; // File to upload, we'll use the S3 class since it exists
$bucketName = uniqid('s3test'); // Temporary bucket

// If you want to use PECL Fileinfo for MIME types:
Expand Down Expand Up @@ -49,11 +47,18 @@
if ($s3->putObjectFile($uploadFile, $bucketName, baseName($uploadFile), S3::ACL_PUBLIC_READ)) {
echo "S3::putObjectFile(): File copied to {$bucketName}/".baseName($uploadFile).PHP_EOL;


// Get the contents of our bucket
$contents = $s3->getBucket($bucketName);
echo "S3::getBucket(): Files in bucket {$bucketName}: ".print_r($contents, 1);


// Get object info
$info = $s3->getObjectInfo($bucketName, baseName($uploadFile));
echo "S3::getObjecInfo(): Info for {$bucketName}/".baseName($uploadFile).': '.print_r($info, 1);

// You can also fetch the object into memory:

// You can also fetch the object into memory
// var_dump("S3::getObject() to memory", $s3->getObject($bucketName, baseName($uploadFile)));

// Or save it into a file (write stream)
Expand All @@ -63,9 +68,26 @@
// var_dump("S3::getObject() to resource", $s3->getObject($bucketName, baseName($uploadFile), fopen('savefile.txt', 'wb')));


// Get the contents of our bucket
$contents = $s3->getBucket($bucketName);
echo "S3::getBucket(): Files in bucket {$bucketName}: ".print_r($contents, 1);

// Get the access control policy for a bucket:
// $acp = $s3->getAccessControlPolicy($bucketName);
// echo "S3::getAccessControlPolicy(): {$bucketName}: ".print_r($acp, 1);

// Update an access control policy ($acp should be the data returned by S3::getAccessControlPolicy())
// $s3->setAccessControlPolicy($bucketName, '', $acp);
// $acp = $s3->getAccessControlPolicy($bucketName);
// echo "S3::getAccessControlPolicy(): {$bucketName}: ".print_r($acp, 1);


// Enable logging for a bucket (remember, logbucket must be writable by the log group too):
// $s3->enableBucketLogging($bucketName, 'logbucket', 'prefix');

// if (($logging = $s3->getBucketLogging($bucketName)) !== false) {
// echo "S3::getBucketLogging(): Logging for {$bucketName}: ".print_r($contents, 1);
// } else {
// echo "S3::getBucketLogging(): Logging for {$bucketName} not enabled\n";
// }


// Delete our file
if ($s3->deleteObject($bucketName, baseName($uploadFile))) {
Expand Down

0 comments on commit 0154802

Please sign in to comment.