亚马逊PHP SDK列表对象

1dkrff03  于 2023-02-28  发布在  PHP
关注(0)|答案(2)|浏览(109)

我需要在我的S3上显示存储桶内容,我使用Amazon的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

我相信在'目录'下面的部分是我要找的,但是我怎么访问它呢?我习惯于接收数组,在那里我可以知道键是什么,以及如何访问,但是这里对我来说很难,有人猜吗?

u4vypkhs

u4vypkhs1#

尝试以下步骤以列出每个对象的关键元素:

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

1l5u6lss2#

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

$contents = $objects['Contents'];

相关问题