Skip to content
A standalone Amazon S3 (REST) client for PHP 5.2.x using CURL that does not require PEAR.
PHP
Branch: master
Clone or download
Pull request Compare This branch is 6 commits ahead, 6 commits behind tpyo:master.
Latest commit 62bab52 Apr 14, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Added composer.json and .gitignore Jun 25, 2013
README.md Merge branch 'sign_v4' Dec 15, 2016
S3.php Merge branch 'sign_v4' Apr 14, 2017
composer.json Updated composer.json Jun 26, 2013
example-cloudfront.php Support for CloudFront and updates to setBucketLogging() Nov 27, 2008
example-form.php More updates for 0.4.0 release Jul 20, 2009
example-wrapper.php No commit message May 6, 2008
example.php

README.md

Amazon S3 PHP Class

Usage

OO method (e,g; $s3->getObject(...)):

$s3 = new S3($awsAccessKey, $awsSecretKey);

Statically (e,g; S3::getObject(...)):

S3::setAuth($awsAccessKey, $awsSecretKey);

AWS V4 Signature

$s3->setSignatureVersion('v4);

Or statically

S3::setSignatureVersion('v4');

Object Operations

Uploading objects

Put an object from a file:

S3::putObject(S3::inputFile($file, false), $bucketName, $uploadName, S3::ACL_PUBLIC_READ)

Put an object from a string and set its Content-Type:

S3::putObject($string, $bucketName, $uploadName, S3::ACL_PUBLIC_READ, array(), array('Content-Type' => 'text/plain'))

Put an object from a resource (buffer/file size is required - note: the resource will be fclose()'d automatically):

S3::putObject(S3::inputResource(fopen($file, 'rb'), filesize($file)), $bucketName, $uploadName, S3::ACL_PUBLIC_READ)

Retrieving objects

Get an object:

S3::getObject($bucketName, $uploadName)

Save an object to file:

S3::getObject($bucketName, $uploadName, $saveName)

Save an object to a resource of any type:

S3::getObject($bucketName, $uploadName, fopen('savefile.txt', 'wb'))

Copying and deleting objects

Copy an object:

S3::copyObject($srcBucket, $srcName, $bucketName, $saveName, $metaHeaders = array(), $requestHeaders = array())

Delete an object:

S3::deleteObject($bucketName, $uploadName)

Bucket Operations

Get a list of buckets:

S3::listBuckets()  // Simple bucket list
S3::listBuckets(true)  // Detailed bucket list

Create a bucket:

S3::putBucket($bucketName)

Get the contents of a bucket:

S3::getBucket($bucketName)

Delete an empty bucket:

S3::deleteBucket($bucketName)

Progress Function

Add a progress function when S3 downloading / uploading

S3::setProgressFunction('progress');

function progress($resource,$download_size, $downloaded, $upload_size, $uploaded)
{
    if($download_size > 0)
         echo $downloaded / $download_size  * 100;
    ob_flush();
    flush();
    sleep(1); // just to see effect
}
You can’t perform that action at this time.