-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccess_S3.php
30 lines (25 loc) · 907 Bytes
/
Access_S3.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
//Install and initialize AWS SDK
require 'AWSSDK/aws-autoloader.php';
//Declare the S3Client and AwsException class
use Aws\S3\S3Client;
use Aws\Exception\AwsException;
//Build the connection to S3
$s3Client = new Aws\S3\S3Client([
'version' => 'latest',
'region' => AWS_S3_REGION, //Your region
'credentials' => array(
'key' => AWS_ACCESS_TOKEN, //Your Access Key ID
'secret' => AWS_SECRET_TOKEN //Your Secret Access Key
)
]);
//Use getIterator to get the details of files
$iterator = $s3Client->getIterator('ListObjects', array(
'Bucket' => AWS_S3_BUCKET
));
//List files name and download links
foreach ($iterator as $object) {
echo "File name is ".$object['Key']."\n";
echo "File link is ".$s3Client->getObjectUrl(AWS_S3_BUCKET, urldecode(FilePath), '+30 minutes');."\n";
}
?>