|
| 1 | +# Amazon S3 PHP Class |
| 2 | + |
| 3 | +## Usage |
| 4 | + |
| 5 | +OO method (e,g; $s3->getObject(...)): |
| 6 | + |
| 7 | +```php |
| 8 | +$s3 = new S3($awsAccessKey, $awsSecretKey); |
| 9 | +``` |
| 10 | + |
| 11 | +Statically (e,g; S3::getObject(...)): |
| 12 | + |
| 13 | +```php |
| 14 | +S3::setAuth($awsAccessKey, $awsSecretKey); |
| 15 | +``` |
| 16 | + |
| 17 | +### Object Operations |
| 18 | + |
| 19 | +#### Uploading objects |
| 20 | + |
| 21 | +Put an object from a file: |
| 22 | + |
| 23 | +```php |
| 24 | +S3::putObject(S3::inputFile($file, false), $bucketName, $uploadName, S3::ACL_PUBLIC_READ) |
| 25 | +``` |
| 26 | + |
| 27 | +Put an object from a string and set its Content-Type: |
| 28 | + |
| 29 | +```php |
| 30 | +S3::putObject($string, $bucketName, $uploadName, S3::ACL_PUBLIC_READ, array(), array('Content-Type' => 'text/plain')) |
| 31 | +``` |
| 32 | + |
| 33 | +Put an object from a resource (buffer/file size is required - note: the resource will be fclose()'d automatically): |
| 34 | + |
| 35 | +```php |
| 36 | +S3::putObject(S3::inputResource(fopen($file, 'rb'), filesize($file)), $bucketName, $uploadName, S3::ACL_PUBLIC_READ) |
| 37 | +``` |
| 38 | + |
| 39 | +#### Retrieving objects |
| 40 | + |
| 41 | +Get an object: |
| 42 | + |
| 43 | +```php |
| 44 | +S3::getObject($bucketName, $uploadName) |
| 45 | +``` |
| 46 | + |
| 47 | +Save an object to file: |
| 48 | + |
| 49 | +```php |
| 50 | +S3::getObject($bucketName, $uploadName, $saveName) |
| 51 | +``` |
| 52 | + |
| 53 | +Save an object to a resource of any type: |
| 54 | + |
| 55 | +```php |
| 56 | +S3::getObject($bucketName, $uploadName, fopen('savefile.txt', 'wb')) |
| 57 | +``` |
| 58 | + |
| 59 | +#### Copying and deleting objects |
| 60 | + |
| 61 | +Copy an object: |
| 62 | + |
| 63 | +```php |
| 64 | +S3::copyObject($srcBucket, $srcName, $bucketName, $saveName, $metaHeaders = array(), $requestHeaders = array()) |
| 65 | +``` |
| 66 | + |
| 67 | +Delete an object: |
| 68 | + |
| 69 | +```php |
| 70 | +S3::deleteObject($bucketName, $uploadName) |
| 71 | +``` |
| 72 | + |
| 73 | +### Bucket Operations |
| 74 | + |
| 75 | +Get a list of buckets: |
| 76 | + |
| 77 | +```php |
| 78 | +S3::listBuckets() // Simple bucket list |
| 79 | +S3::listBuckets(true) // Detailed bucket list |
| 80 | +``` |
| 81 | + |
| 82 | +Create a bucket: |
| 83 | + |
| 84 | +```php |
| 85 | +S3::putBucket($bucketName) |
| 86 | +``` |
| 87 | + |
| 88 | +Get the contents of a bucket: |
| 89 | + |
| 90 | +```php |
| 91 | +S3::getBucket($bucketName) |
| 92 | +``` |
| 93 | + |
| 94 | +Delete an empty bucket: |
| 95 | + |
| 96 | +```php |
| 97 | +S3::deleteBucket($bucketName) |
| 98 | +``` |
| 99 | + |
0 commit comments