简体   繁体   English

如何仅在 PHP 中列出 S3 中的文件夹

[英]How to only list folders in S3 in PHP

I know that to get the list of all the contents of a bucket you do something like this:我知道要获取存储桶中所有内容的列表,您可以执行以下操作:

$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region'  => 'us-east-1',
'credentials' => array(
    'key' => <key>,
    'secret' => <secret>
)
]);
$objects = $s3->getIterator('ListObjects', array('Bucket' => <bucketname>, 'Prefix' => 'downloads/'));

Is there a way to only get the list of folders inside 1 specific folder instead of the entire recursive list of contents?有没有办法只获取 1 个特定文件夹中的文件夹列表而不是整个递归内容列表?

<?php
    use Aws\S3\S3Client;

    require_once 'vendor/autoload.php';

    $s3 = new Aws\S3\S3Client([
            'version' => 'latest',
            'region'  => 'us-east-1',
            'credentials' => array(
                'key' => <key>,
                'secret' => <secret>
            )
        ]);
    $objects = $s3->ListObjects(['Bucket' => <bucketname>, 'Delimiter'=>'/', 'Prefix' => 'downloads']);
    var_dump($objects);
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM