Php 如果文件已上载或未上载,如何检查机架空间?

Php 如果文件已上载或未上载,如何检查机架空间?,php,guzzle,rackspace-cloud,rackspace,rackspace-cloudfiles,Php,Guzzle,Rackspace Cloud,Rackspace,Rackspace Cloudfiles,我正在使用Rackspace PHP API,在这里我需要检查文件,如果它存在,那么做一些事情,如果不存在,那么做一些事情 try { $file = $container->getObject($end_element); $fileExists = TRUE; } catch(Exception $e) { $fileExists = FALSE; } if ($fileExists) { // File is their, it needs to be rewrite

我正在使用Rackspace PHP API,在这里我需要检查文件,如果它存在,那么做一些事情,如果不存在,那么做一些事情

try {
  $file = $container->getObject($end_element);
  $fileExists = TRUE;
}
catch(Exception $e) {
  $fileExists = FALSE;
}
if ($fileExists) {
  // File is their, it needs to be rewrite/overwrite
  $file->setContent(fopen('sites/default/files/rackspace/' . $end_element, 'r+'));
  $file->update();
  // I'm getting this http://docs.rackspace.com/sdks/api/php/class-OpenCloud.ObjectStore.Resource.DataObject.html which I printted print_r($file->update());
}
else {
  // New file just to upload
  $container->uploadObject($end_element, fopen('sites/default/files/rackspace/' . $end_element, 'r+'), array());
}

要查看远程容器中是否存在对象,请尝试使用如下方法:

if ($container->objectExists('objectName.txt')) {
   // The object exists
} else {
   // The object doesn't exist
}
这将在该对象上执行HEAD请求,将任何404故障响应包装在try/catch块中


在查找对象的创建日期方面,API只告诉您上次修改的日期。如果自第一次上载对象后尚未修改该对象,则此日期将为创建日期

要查找上次修改的日期时间,您需要运行:

$object = $container->getObject('objectName.txt');
$created = $object->getLastModified();

是否也可以获取上传文件的时间?