【发布时间】:2011-03-20 23:02:28
【问题描述】:
我正在使用下面的代码来获取我的云服务器上的文件timestamps,然后删除任何超过一定年龄的文件。
目前,代码设置为删除任何超过 10 分钟的内容以进行测试。
但是它会删除所有内容,即使我上传了一些文件然后在 10 秒后运行脚本。
是否有一些我没有看到的小问题?
$auth->authenticate();
//connect
$conn = new CF_Connection($auth);
//create a handle for the CLOUD FILES container we want to delete from
$daily_dose = $conn->get_container('daily_dose');
//delete the obeject
$daily_packages = $daily_dose->list_objects();
//print_r($daily_packages);
//$public_container = $conn->get_container("public");
//$file_age = 86400; // 1 day in seconds
$file_age = 600; // 10 minutes
echo 'current time: ';
echo $current_time = time();
echo '<br>';
echo 'time offset: ';
echo $previous_day = $current_time - $file_age;
echo '<br>';
foreach($daily_packages as $package)
{
echo $item = $daily_dose->get_object($package);
$modified = $item->last_modified;
echo ' ' . $modified;
echo ' -> ' . strtotime($modified);
echo '<br>';
//If the modified time of the file is less the current time - 1 day in seconds (older than 1 day) delete it
if ( $modified < $previous_day )
{
//delete the file
$daily_dose->delete_object($item);
}
}
【问题讨论】:
-
你能不能把
echo的内容也包括在内,这对我们也很有用。 -
$item->last_modified中到底是什么?事实上,它是与time()返回的时间戳相同吗?假设您对代码进行更多检测:echo ' ' . $modified . ' -> ' . strtotime($modified) . '; comparing ' . $modified . ' with ' . $previous_day . ' => ' . ($modified < $previous_day) . <br>;或类似的东西;输出亮了吗? -
last_modified是一个类变量,它将返回类似Sun, 20 Mar 2011 23:09:36 GMT的内容,然后我将其转换为timestamps
标签: php datetime timestamp unix-timestamp