简体   繁体   English

last_modified出现问题-Rackspace Cloud Files(PHP API)

[英]Trouble with last_modified - Rackspace Cloud Files (PHP API)

Using Rackspace cloud files as a backup repository but new to their PHP API. 使用Rackspace云文件作为备份存储库,但是它们是PHP API的新功能。 I want to delete files past a certail age but having difficulty returning the last_modified date using the api. 我想删除文件,但无法使用api返回last_modified日期。

$container = $conn->get_container('tmp');
$files = $container->list_objects();
foreach ($files as $file) {
  echo $file;  // echo filename
  echo $file->last_modified();  // this syntax is incorrect
  }

list_objects returns an array of strings, the names of the objects. list_objects返回一个字符串数组,即对象的名称。 You can also get PHP objects that allow you to use OOP to do things to those objects. 您还可以获取PHP对象,这些对象允许您使用OOP对那些对象执行操作。 So changing as little of your code as possible, we can convert the strings to objects: 因此,只需更改尽可能少的代码,我们就可以将字符串转换为对象:

$container = $conn->get_container('tmp');
$files = $container->list_objects();
foreach ($files as $file) {
  echo $file;  // echo filename
  $file_obj = $container->get_object($file);
  echo $file_obj->last_modified; 
}

A little faster, just get an array of objects instead: 快一点,只需获取一个对象数组即可:

$container = $conn->get_container('tmp');
$files = $container->get_objects();
foreach ($files as $file) {
  echo $file->name;  // echo filename
  echo $file->last_modified;  
}

Node that code has not been tested, but should get you pretty close to something that works. 该代码尚未经过测试的节点,但应该可以使您接近可行的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM