PHP code example of idapgroup / s3-storage-sdk

1. Go to this page and download the library: Download idapgroup/s3-storage-sdk 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/ */

    

idapgroup / s3-storage-sdk example snippets




dapGroup\S3StorageSdk\Storage\S3Storage;

$s3Client = new S3Client([
            'region' => 'S3_REGION',
            'version' => 'S3_API_VERSION',
            'credentials' => [
                'key' => 'S3_KEY',
                'secret' => 'S3_SECRET'
            ],
        ]);

$readStorage = new S3Storage($s3Client, 'S3_READ_BUCKET', 'S3_REGION');
$writeStorage = new S3Storage($s3Client, 'S3_WRITE_BUCKET', 'S3_REGION');

// Create an instance of class that implements UploadedFileInterface
$file = new UploadedFile();
$readStorage->save($file, 'filename');

// Create an instance of class that implements S3FileInterface or extends S3File
$imageFile = new S3File('file_path', $writeStorage->getBucket());
$readStorage->transfer($imageFile);

$readStorage->delete('file_path');

$readStorage->has('file_path');

$readStorage->get('file_path');

$bucketName = $readStorage->getBucket();

$bucketRegion = $readStorage->getRegion();

$bucketName = $writeStorage->buildPutUrl('filename');