Last active
March 31, 2023 09:13
-
-
Save thomaskanzig/0294864c9931031d9a01969a27046e32 to your computer and use it in GitHub Desktop.
Revisions
-
thomaskanzig revised this gist
Mar 31, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # Get, list and delete objects from AWS S3 Bucket As requirement, install the [AWS SDK for PHP](https://github.com/aws/aws-sdk-php) library to connect AWS S3. First of all you need to connect to your AWS S3: -
thomaskanzig renamed this gist
Mar 31, 2023 . 1 changed file with 27 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # List object from AWS S3 Bucket As requirement, install the [AWS SDK for PHP](https://github.com/aws/aws-sdk-php) library to connect AWS S3. First of all you need to connect to your AWS S3: ```bash @@ -23,6 +23,12 @@ $config = $client = new \Aws\S3\S3Client($config); ``` #### List objects: ```bash $result = $client->listObjects([ 'Bucket' => 'bucket-name', 'Prefix' => 'sub/directory/' @@ -36,4 +42,23 @@ foreach ($result['Contents'] as $key => $object) { echo $object['Key'] . "<br>"; } ``` #### Get object: ```bash $object = $client->getObject(array( 'Bucket' => 'bucket-name', 'Key' => 'sub/directory/image.jpg' )); ``` #### Delete object: ```bash $client->deleteObject([ 'Bucket' => 'bucket-name', 'Key' => 'sub/directory/image.jpg' ]); ``` -
thomaskanzig revised this gist
Mar 28, 2023 . No changes.There are no files selected for viewing
-
thomaskanzig created this gist
Mar 28, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ # List object from AWS S3 Bucket As requirement, install the [AWS SDK for PHP](https://github.com/aws/aws-sdk-php) library to connect AWS S3. ```bash require 'vendor/autoload.php'; use Aws\S3\S3Client; use Aws\Exception\AwsException; $config = [ 'version' => 'latest', 'region' => '', 'endpoint' => '[cluster-url]', 'credentials' => [ 'key' => '[access-key]', 'secret' => '[secret-key]', ], ]; $client = new \Aws\S3\S3Client($config); $result = $client->listObjects([ 'Bucket' => 'bucket-name', 'Prefix' => 'sub/directory/' ]); foreach ($result['Contents'] as $key => $object) { // Is the value of prefix. if (0 === $key) { continue; } echo $object['Key'] . "<br>"; } ```