PHP code example of buuum / s3

1. Go to this page and download the library: Download buuum/s3 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

buuum / s3 example snippets


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';

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

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

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

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

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

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

$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');

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


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


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

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

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

$buckets = S3::listBuckets();

S3::putBucket($bucketName);

S3::deleteBucket($bucketName);

S3::listFiles($bucketName);