public function mkdir($options) {
    $report_errors = ($options | STREAM_REPORT_ERRORS) != 0;
    $headers = $this->getOAuthTokenHeader(parent::WRITE_SCOPE);
    if ($headers === false) {
      if ($report_errors) {
        trigger_error("Unable to acquire OAuth token.", E_USER_WARNING);
      }
      return false;
    }

    // Use x-goog-if-generation-match so we only create a new object.
    $headers['x-goog-if-generation-match'] = 0;
    $headers['Content-Range'] = sprintf(parent::FINAL_CONTENT_RANGE_NO_DATA, 0);

    $url = $this->createObjectUrl($this->bucket_name, $this->object_name);
    $http_response = $this->makeHttpRequest($url, "PUT", $headers);

    if (false === $http_response) {
      if ($report_errors) {
        trigger_error("Unable to connect to Google Cloud Storage Service.",
                      E_USER_WARNING);
      }
      return false;
    }

    // The status code precondition failed means that the 'directoy' already
    // existed.
    $status_code = $http_response['status_code'];
    if ($status_code != HttpResponse::OK &&
        $status_code != HttpResponse::PRECONDITION_FAILED) {
      if ($report_errors) {
        trigger_error($this->getErrorMessage($status_code,
                                             $http_response['body']),
                    E_USER_WARNING);
      }
      return false;
    }
    return ($status_code === HttpResponse::OK);
  }
public function mkdir($options) {
    $report_errors = ($options | STREAM_REPORT_ERRORS) != 0;
    $headers = $this->getOAuthTokenHeader(parent::WRITE_SCOPE);
    if ($headers === false) {
      if ($report_errors) {
        trigger_error("Unable to acquire OAuth token.", E_USER_WARNING);
      }
      return false;
    }

    // Use x-goog-if-generation-match so we only create a new object.
    $headers['x-goog-if-generation-match'] = 0;
    $headers['Content-Range'] = sprintf(parent::FINAL_CONTENT_RANGE_NO_DATA, 0);

    $url = $this->createObjectUrl($this->bucket_name, $this->object_name);
    $http_response = $this->makeHttpRequest($url, "PUT", $headers);

    if (false === $http_response) {
      if ($report_errors) {
        trigger_error("Unable to connect to Google Cloud Storage Service.",
                      E_USER_WARNING);
      }
      return false;
    }

    // The status code precondition failed means that the 'directoy' already
    // existed.
    $status_code = $http_response['status_code'];
    if ($status_code != HttpResponse::OK &&
        $status_code != HttpResponse::PRECONDITION_FAILED) {
      if ($report_errors) {
        trigger_error($this->getErrorMessage($status_code,
                                             $http_response['body']),
                    E_USER_WARNING);
      }
      return false;
    }
    return ($status_code === HttpResponse::OK);
  }
public function mkdir ( $ options ) { $ report_errors = ( $ options | STREAM_REPORT_ERRORS ) != 0 ; $ headers = $ this -> getOAuthTokenHeader ( parent :: WRITE_SCOPE ) ; if ( $ headers === false ) { if ( $ report_errors ) { trigger_error ( "Unable to acquire OAuth token." , E_USER_WARNING ) ; } return false ; } // Use x-goog-if-generation-match so we only create a new object. $ headers [ 'x-goog-if-generation-match' ] = 0 ; $ headers [ 'Content-Range' ] = sprintf ( parent :: FINAL_CONTENT_RANGE_NO_DATA , 0 ) ; $ url = $ this -> createObjectUrl ( $ this -> bucket_name , $ this -> object_name ) ; $ http_response = $ this -> makeHttpRequest ( $ url , "PUT" , $ headers ) ; if ( false === $ http_response ) { if ( $ report_errors ) { trigger_error ( "Unable to connect to Google Cloud Storage Service." , E_USER_WARNING ) ; } return false ; } // The status code precondition failed means that the 'directoy' already // existed. $ status_code = $ http_response [ 'status_code' ] ; if ( $ status_code != HttpResponse :: OK && $ status_code != HttpResponse :: PRECONDITION_FAILED ) { if ( $ report_errors ) { trigger_error ( $ this -> getErrorMessage ( $ status_code , $ http_response [ 'body' ] ) , E_USER_WARNING ) ; } return false ; } return ( $ status_code === HttpResponse :: OK ) ; }
Make a 'directory' in Google Cloud Storage.

@param mixed $options A bitwise mask of values, such as
STREAM_MKDIR_RECURSIVE.

@return bool <code>true</code> if the directory was created,
<code>false</code> otherwise.

TODO: If the STREAM_MKDIR_RECURSIVE bit is not set in the options then we
should validate that the entire path exists before we create the directory.
Make a directory in Google Cloud Storage .