buuum/s3

A simple aws s3 class

v1.0.0 2017-07-11 10:28 UTC

This package is auto-updated.

Last update: 2024-04-17 19:43:58 UTC


README

Packagist license

Install

System Requirements

You need PHP >= 5.5.0 to use Buuum\S3 but the latest stable version of PHP is recommended.

Composer

Buuum\S3 is available on Packagist and can be installed using Composer:

composer require buuum/s3

Manually

You may use your own autoloader as long as it follows PSR-0 or PSR-4 standards. Just put src directory contents in your vendor directory.

CONSTANTS

const ACL_PRIVATE = 'private';
const ACL_PUBLIC_READ = 'public-read';
const ACL_PUBLIC_READ_WRITE = 'public-read-write';
const ACL_AUTHENTICATED_READ = 'authenticated-read';

const STORAGE_CLASS_STANDARD = 'STANDARD';
const STORAGE_CLASS_RRS = 'REDUCED_REDUNDANCY';
const STORAGE_CLASS_STANDARD_IA = 'STANDARD_IA';

USAGE

INITIALIZE

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

SET and GET default bucket

S3::setBucket($bucket);
S3::getBucket();

SET urls

$urls = [
    'http'  => 'http://s3-eu-west-1.amazonaws.com/bucket',
    'https' => 'https://s3-eu-west-1.amazonaws.com/bucket'
];
S3::setUrls($urls);

SET ACL AND STORAGE (Optional, default acl = S3::ACL_PUBLIC_READ, storage = S3::STORAGE_CLASS_STANDARD)

S3::setAcl(S3::ACL_PRIVATE);
S3::setStorage(S3::STORAGE_CLASS_STANDARD);

UPLOADING OBJECTS

Put an object from $_FILES

S3::putObject($_FILES['filename']['tmp_name'], $_FILES['filename']['name']);

Put an object from string

S3::putObjectString(file_get_contents('bg.jpg'), 'bg.jpg');

Put an object from url

$url = 'https://www.enterprise.es/content/dam/ecom/utilitarian/emea/business-rentals/business-rental-band.jpg.wrend.1280.720.jpeg';
S3::putObjectUrl($url, 'car.jpg');

Set headers on put objects 1.- as parameter

$headers = [
    'Cache-Control' => 'max-age=2592000',
    'Expires'       => 2592000,
];
S3::putObjectUrl($url, 'car.jpg', $headers);

2.- as defaultheaders

$headers = [
    'Cache-Control' => 'max-age=2592000',
    'Expires'       => 2592000,
];
S3::setDefaultHeaders($headers);

Put response

array(4) {
  ["code"]=> int(200)
  ["error"]=>  bool(false)
  ["message"]=>  string(0) ""
  ["url"]=>
  array(3) {
    ["default"]=>
    string(53) "https://bucket.s3.amazonaws.com/20130726_173253.jpg"
    ["http"]=>
    string(62) "http://s3-eu-west-1.amazonaws.com/bucket/20130726_173253.jpg"
    ["https"]=>
    string(63) "https://s3-eu-west-1.amazonaws.com/bucket/20130726_173253.jpg"
  }
}

RETRIEVING OBJECTS

Get an object:

$response = S3::getObject('bg.jpg',$bucketName);
file_put_contents('bg.jpg', $response->message);

DELETING OBJECTS

Delete an object:

S3::deleteObject('bg.jpg',$bucketName);

Delete an object from url:

S3::deleteObjectUrl('https://s3-eu-west-1.amazonaws.com/bucket/20130726_173253.jpg');

BUCKETS

Get a list of buckets:

$buckets = S3::listBuckets();

Create a bucket:

S3::putBucket($bucketName);

Delete an empty bucket:

S3::deleteBucket($bucketName);

FILES

Get a list of files in bucket

S3::listFiles($bucketName);

LICENSE

The MIT License (MIT)

Copyright (c) 2016

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.