Quick way to list all files in Amazon S3 bucket?

前端 未结 28 1810
星月不相逢
星月不相逢 2020-11-28 01:32

I have an amazon s3 bucket that has tens of thousands of filenames in it. What\'s the easiest way to get a text file that lists all the filenames in the bucket?

28条回答
  •  温柔的废话
    2020-11-28 01:42

    function showUploads(){
        if (!class_exists('S3')) require_once 'S3.php';
        // AWS access info
        if (!defined('awsAccessKey')) define('awsAccessKey', '234567665464tg');
        if (!defined('awsSecretKey')) define('awsSecretKey', 'dfshgfhfghdgfhrt463457');
        $bucketName = 'my_bucket1234';
        $s3 = new S3(awsAccessKey, awsSecretKey);
        $contents = $s3->getBucket($bucketName);
        echo "
    List of Files in bucket : {$bucketName}
    "; $n = 1; foreach ($contents as $p => $v): echo $p."
    "; $n++; endforeach; }

提交回复
热议问题