腾讯云 对象存储 文件列表

 $cosClient = new Client(array(
            'region' => env('Q_CLOUD.region'),
            'schema' => 'http',
            'credentials' => array(
                'secretId' => env('Q_CLOUD.SECRETID'),
                'secretKey' => env('Q_CLOUD.SECRETKEY'),
            )
        ));

        $result = $cosClient->listObjects(array(
            'Bucket' => env('q_cloud.bucket'),
            'Prefix' => 'hipc/test/',
            'MaxKeys' => 10,
        ));
       
        if (isset($result['Contents'])) {
            foreach ($result['Contents'] as $rt) {
                // 打印key
                echo($rt['Key'] . "\n");
            }
        }

结果

hipc/test/62d50316c395f1658127126.png
hipc/test/62d50321a7c121658127137.png
hipc/test/62d50424a9b681658127396.png
hipc/test/62d504258a52f1658127397.png
hipc/test/62d50874b18a71658128500.png
hipc/test/62d50882e14bb1658128514.png

最新上传的文件排最后

Prefix 是路径
MaxKeys 查询数量

不支持按时间排序

posted @ 2022-07-18 15:19  冯元春  阅读(123)  评论(0)    收藏  举报