PHP code example of benmajor / sirv-s3-client

1. Go to this page and download the library: Download benmajor/sirv-s3-client 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/ */

    

benmajor / sirv-s3-client example snippets




# Include Composer autoloader:
ient;

$client = new SirvS3Client(
  'SIRV_S3_BUCKET',
  'SIRV_S3_KEY',
  'SIRV_S3_SECRET'
);

if( $client->testConnection() ) {
  # Connection is valid and ready.
} else {
  # Something went wrong with the connection.
}

$client->checkIfObjectExists('/example/folder');

$client->checkIfObjectExists('example/folder', 'image.jpg');

$client->getBucketContents('example/folder');

$client->createFolder('example/new-folder');

$client->uploadFile(
  'example/folder/my-picture.jpg',
  '/path/to/local/my-picture.jpg'
);

$client->uploadFile(
  'example/folder/'.basename($_FILES['uploaded']['name']),
  $_FILES['uploaded']['TMP_NAME']
);

$file = $client->getFile('/path/to/file.jpg');

if( ! empty($file) ) {
  file_put_contents('file.jpg', $file);
}

$client->copyFile(
  'path/to/image.jpg',
  'another/path/image.jpg'
);

$client->copyFile(
	'path/to/image.jpg',
	'path/to/image-copy.jpg'
);

$client->renameFile(
  'example/folder/image.jpg',
  'example/folder/renamed.jpg'
);

$client->deleteFile('example/folder/image.jpg');