亚马逊PHP SDK列表对象

时间:2012-11-29 16:30:06

标签: php amazon-s3 amazon

我需要在S3上显示存储桶内容,而我正在使用亚马逊的PHP SDK。 我的代码只是

 $objects = $s3->list_objects("mybucket",array("max-keys"=>5));
 var_dump($objects);

我从服务器得到的回复对我来说非常复杂 - 它的本质是

Object(CFResponse)[107]
    public 'header' => 
    array (size=11)
      'x-amz-id-2' => string      
    ...
    public 'body' => 
    object(CFSimpleXML)[106]
      public '@attributes' => 
        array (size=1)
          'ns' => string 'http://s3.amazonaws.com/doc/2006-03-01/' (length=39)
      public 'Name' => string 'cdneu.2yourfacecdn.com' (length=22)
      public 'Prefix' => 
        object(CFSimpleXML)[3]
      public 'Marker' => 
        object(CFSimpleXML)[105]
      public 'MaxKeys' => string '5' (length=1)
      public 'IsTruncated' => string 'true' (length=4)
      public 'Contents' => 
        array (size=5)
          0 => 
            object(CFSimpleXML)[104]
              ...
          1 => 
            object(CFSimpleXML)[103]
              ...
          2 => 
            object(CFSimpleXML)[102]
              ...
          3 => 
            object(CFSimpleXML)[101]
              ...
          4 => 
            object(CFSimpleXML)[100]
              ...
         public 'status' => int 200

我相信'内容'下的部分是我正在寻找的,但我该如何访问它?我习惯接收数组,我可以弄清楚键是什么以及如何访问但这对我来说很难, 任何猜测?

2 个答案:

答案 0 :(得分:1)

尝试这个以列出每个对象的关键元素:

$s3 = new AmazonS3();
$objects = $s3->list_objects("YOUR BUCKET NAME",array("max-keys"=>5));
foreach ($objects->body->Contents as $item){
    print_r($item->Key."");
}

答案 1 :(得分:0)

您可以按如下方式访问内容

$contents = $objects['Contents'];