Amazon S3 and PHP | How to list only top level folders in a bucket

| By Webner

Sample code:

$result= $client->listObjects(array("Bucket" => $bucket,"Delimiter" => "/"));
$files = $response2->getPath('Contents');
foreach ($result['CommonPrefixes'] as $object)
      echo $object['Prefix']';

This will list only the top level folder. If we do not use delimiter with listObject function then it will give list of all the files with its respective path.

Webner Solutions is a Software Development company focused on developing CRM apps (Salesforce, Zoho), LMS Apps (Moodle/Totara), Websites and Mobile apps. If you need Web development or any other software development assistance please contact us at

Leave a Reply

Your email address will not be published. Required fields are marked *