I have working code which returns all the files under s3 bucket. I have to get today's uploaded files for further processing.
Code to get files :
use Aws\S3\S3Client;
$s3Client = S3Client::factory(array(
'region' => 'us-east-1',
'version' => '2006-03-01',
'credentials' => array(
'key' => 'XXXX',
'secret' => 'YYYYYYYY'
)
));
$iterator = $s3Client->getIterator('ListObjects', array(
'Bucket' => 'mybucket',
'Prefix' => 'adityamusic',
'Suffix' => '.xlsx',
), array(
'limit' => 999,
'page_size' => 100
));
foreach ($iterator as $object) {
print_r($object['LastModified']);
print_r($object['LastModified']['date']); //this gives error
}
print_r($object['LastModified']) outputs as :
Array
(
[Key] => mymusic/
[LastModified] => Aws\Api\DateTimeResult Object
(
[date] => 2016-08-03 06:20:31
[timezone_type] => 2
[timezone] => Z
)
[ETag] => "sadfasdf2342"
[Size] => 0
[StorageClass] => STANDARD
[Owner] => Array
(
[DisplayName] => test
[ID] => asdfasdfasdf
)
)
I am not able to access date key.
LastModified is an instance of Aws\Api\DateTimeResult class, since DateTimeResult extends \DateTime object, just use format method as you would normally do when working with standard DateTime objects.
echo $object['LastModified']->format(\DateTime::ISO8601)
Read here for more formatting options.
P.S. $object['LastModified']->date will not work because its not designed to be accessed directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With