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

I am trying to connect up an aws bucket to read the contents of the s3 bucket into a database I have set up the connection and it returns the bucket names but I now want the contents of a particular bucket

here is what I have

 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'] . ":
";
 foreach ($blist['Buckets'] as $b) {
  echo "{$b['Name']}\t{$b['CreationDate']}
";
  }

 //view contents

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

for reference I got the above from here :

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

You should define the $bucketname first.

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