68 lines
2.0 KiB
PHP
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require '../vendor/autoload.php';
use Aws\S3\S3Client;
define('AWS_KEY', '34644ff7e004f9d185d7b9850fa6e40c');
define('AWS_SECRET_KEY', 'ff6a83377bad26f522fa2e7e561314a5');
$ENDPOINT = 'https://eu2.contabostorage.com/';
// require the amazon sdk from your composer vendor dir
// Instantiate the S3 class and point it at the desired host
$client = new S3Client([
'region' => 'eu2',
'version' => 'latest',
'endpoint' => $ENDPOINT,
'credentials' => [
'key' => AWS_KEY,
'secret' => AWS_SECRET_KEY
],
// Set the S3 class to use objects.dreamhost.com/bucket
// instead of bucket.objects.dreamhost.com
'use_path_style_endpoint' => true
]);
//LISTING OWNED BUCKETS
// $listResponse = $client->listBuckets();
// $buckets = $listResponse['Buckets'];
// foreach ($buckets as $bucket) {
// echo $bucket['Name'] . "\t" . $bucket['CreationDate'] . "\n";
// }
// CREATING A BUCKET
// $client->createBucket(['Bucket' => 'test']);
// LIST A BUCKETS CONTENT
// $bucketname = 'aqdamy';
// $objectsListResponse = $client->listObjects(['Bucket' => $bucketname]);
// $objects = $objectsListResponse['Contents'] ?? [];
// foreach ($objects as $object) {
// echo $object['Key'] . "\t" . $object['Size'] . "\t" . $object['LastModified'] . "\n";
// }
// CREATING AN OBJECT
// $bucketname = 'aqdamy';
// $client->putObject([
// 'Bucket' => $bucketname,
// 'Key' => 'test/test2/hello.txt',
// 'Body' => "Hello World!"
// ]);
// DOWNLOAD AN OBJECT (TO A FILE)
// $bucketname = 'aqdamy';
// $object = $client->getObject(['Bucket' => $bucketname, 'Key' => '1.jpg']);
// file_put_contents($_SERVER['DOCUMENT_ROOT'].'/1.jpg', $object['Body']->getContents());
// $bucketname = 'aqdamy';
// $hello_url = $client->getObjectUrl($bucketname, '1.jpg');
// echo $hello_url."\n";
// $secret_plans_cmd = $client->getCommand('GetObject', ['Bucket' => $bucketname, 'Key' => '1.jpg']);
// $request = $client->createPresignedRequest($secret_plans_cmd, '+1 hour');
// echo $request->getUri()."\n";