亚马逊PHP SDK清单对象亚马逊、清单、对象、SDK

2023-09-11 10:01:14 作者:往事通缉犯

我需要显示在我的S3的桶含量,我使用亚马逊的PHP SDK。 我的code是简单

I have the need to display the bucket contents on my S3 and I am using Amazon's PHP SDK. My code is simply

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

我从服务器获取的响应非常复杂,我明白 - 它的实质是

The response I get from the server is very complicated for me to understand - It's essence is

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

我相信在'内容'的部分是我正在寻找,但我怎么访问它?我已经习惯了接收阵列在那里我可以找出钥匙,以及如何获取,但该位置对我来说很难, 任何猜测?

I believe the part under the 'Contents' is what I'm looking for but how do I access it ? I'm used to receiving arrays where I can figure out what the keys are and how to access but this here is difficult for me , Any guesses?

推荐答案

试试这个,以列出每个对象的关键要素:

try this in order to list the key element of each object:

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