2012-11-29 78 views
1

我需要在S3上顯示存儲桶內容,並使用亞馬遜的PHP SDK。 我的代碼只是亞馬遜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 

我相信在「內容」的部分是我正在尋找,但我如何訪問它?我習慣於接收陣列,在那裏我可以找出鑰匙是什麼以及如何進入,但這對我來說很困難, 任何猜測?

+0

縮進代碼由4位不工作,任何想法,爲什麼? –

回答

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.""); 
} 
0

您可以訪問的內容如下

$contents = $objects['Contents'];