未定义的变量:bucketname(查看:

时间:2015-01-06 09:29:57

标签: php amazon-web-services amazon-s3

我正在尝试连接aws存储桶以将s3存储桶的内容读入我已设置连接的数据库中,并返回存储桶名称但我现在想要特定存储桶的内容

这是我所拥有的

 use Aws\S3\S3Client;

// Establish connection  with an S3 client.
 $client = S3Client::factory(array(

'key'      => AWS_KEY,
'secret'   => AWS_SECRET_KEY
));

// list owned buckets


 $blist = $client->listBuckets();
 echo "   Buckets belonging to " . $blist['Owner']['ID'] . ":\n";
 foreach ($blist['Buckets'] as $b) {
  echo "{$b['Name']}\t{$b['CreationDate']}\n";
  }

 //view contents

 $o_iter = $client->getIterator('ListObjects', array(
'Bucket' => $bucketname
  ));
 foreach ($o_iter as $o) {
   echo "{$o['Key']}\t{$o['Size']}\t{$o['LastModified']}\n";
  }

供参考我从这里得到了上述内容:

http://docs.dreamobjects.net/s3-examples/php2.html

1 个答案:

答案 0 :(得分:1)

您应首先定义$bucketname

$bucketname = 'The bucket you want to list';
$o_iter = $client->getIterator('ListObjects', array('Bucket' => $bucketname));