OSS\OssClient::doesObjectExist PHP Метод

doesObjectExist() публичный Метод

检测Object是否存在 通过获取Object的Meta信息来判断Object是否存在, 用户需要自行解析ResponseCore判断object是否存在
public doesObjectExist ( string $bucket, string $object, array $options = NULL ) : boolean
$bucket string bucket名称
$object string object名称
$options array
Результат boolean
    public function doesObjectExist($bucket, $object, $options = NULL)
    {
        $this->precheckCommon($bucket, $object, $options);
        $options[self::OSS_BUCKET] = $bucket;
        $options[self::OSS_METHOD] = self::OSS_HTTP_HEAD;
        $options[self::OSS_OBJECT] = $object;
        $response = $this->auth($options);
        $result = new ExistResult($response);
        return $result->getData();
    }

Usage Example

 /**
  * Check whether a file exists.
  *
  * @param string $path
  * @return bool
  */
 public function has($path)
 {
     $object = $this->applyPathPrefix($path);
     try {
         $exists = $this->client->doesObjectExist($this->bucket, $object);
     } catch (OssException $e) {
         return false;
     }
     return $exists;
 }
All Usage Examples Of OSS\OssClient::doesObjectExist