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

Author - 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 webdevelopment@webners.com

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

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