function write($data=NULL, $bytes=0, $verify=True)
    {
        if (!$data) {
            throw new SyntaxException("Missing data source.");
        }
        if ($bytes > MAX_OBJECT_SIZE) {
            throw new SyntaxException("Bytes exceeds maximum object size.");
        }
        if ($verify) {
            if (!$this->_etag_override) {
                $this->etag = $this->compute_md5sum($data);
            }
        } else {
            $this->etag = NULL;
        }

        $close_fh = False;
        if (!is_resource($data)) {
            # A hack to treat string data as a file handle.  php://memory feels
            # like a better option, but it seems to break on Windows so use
            # a temporary file instead.
            #
            $fp = fopen("php://temp", "wb+");
            #$fp = fopen("php://memory", "wb+");
            fwrite($fp, $data, strlen($data));
            rewind($fp);
            $close_fh = True;
            $this->content_length = (float) strlen($data);
            if ($this->content_length > MAX_OBJECT_SIZE) {
                throw new SyntaxException("Data exceeds maximum object size");
            }
            $ct_data = substr($data, 0, 64);
        } else {
            $this->content_length = $bytes;
            $fp = $data;
            $ct_data = fread($data, 64);
            rewind($data);
        }

        $this->_guess_content_type($ct_data);

        list($status, $reason, $etag) =
                $this->container->cfs_http->put_object($this, $fp);
        #if ($status == 401 && $this->_re_auth()) {
        #    return $this->write($data, $bytes, $verify);
        #}
        if ($status == 412) {
            if ($close_fh) { fclose($fp); }
            throw new SyntaxException("Missing Content-Type header");
        }
        if ($status == 422) {
            if ($close_fh) { fclose($fp); }
            throw new MisMatchedChecksumException(
                "Supplied and computed checksums do not match.");
        }
        if ($status != 201) {
            if ($close_fh) { fclose($fp); }
            throw new InvalidResponseException("Invalid response (".$status."): "
                . $this->container->cfs_http->get_error());
        }
        if (!$verify) {
            $this->etag = $etag;
        }
        if ($close_fh) { fclose($fp); }
        return True;
    }
function write($data=NULL, $bytes=0, $verify=True)
    {
        if (!$data) {
            throw new SyntaxException("Missing data source.");
        }
        if ($bytes > MAX_OBJECT_SIZE) {
            throw new SyntaxException("Bytes exceeds maximum object size.");
        }
        if ($verify) {
            if (!$this->_etag_override) {
                $this->etag = $this->compute_md5sum($data);
            }
        } else {
            $this->etag = NULL;
        }

        $close_fh = False;
        if (!is_resource($data)) {
            # A hack to treat string data as a file handle.  php://memory feels
            # like a better option, but it seems to break on Windows so use
            # a temporary file instead.
            #
            $fp = fopen("php://temp", "wb+");
            #$fp = fopen("php://memory", "wb+");
            fwrite($fp, $data, strlen($data));
            rewind($fp);
            $close_fh = True;
            $this->content_length = (float) strlen($data);
            if ($this->content_length > MAX_OBJECT_SIZE) {
                throw new SyntaxException("Data exceeds maximum object size");
            }
            $ct_data = substr($data, 0, 64);
        } else {
            $this->content_length = $bytes;
            $fp = $data;
            $ct_data = fread($data, 64);
            rewind($data);
        }

        $this->_guess_content_type($ct_data);

        list($status, $reason, $etag) =
                $this->container->cfs_http->put_object($this, $fp);
        #if ($status == 401 && $this->_re_auth()) {
        #    return $this->write($data, $bytes, $verify);
        #}
        if ($status == 412) {
            if ($close_fh) { fclose($fp); }
            throw new SyntaxException("Missing Content-Type header");
        }
        if ($status == 422) {
            if ($close_fh) { fclose($fp); }
            throw new MisMatchedChecksumException(
                "Supplied and computed checksums do not match.");
        }
        if ($status != 201) {
            if ($close_fh) { fclose($fp); }
            throw new InvalidResponseException("Invalid response (".$status."): "
                . $this->container->cfs_http->get_error());
        }
        if (!$verify) {
            $this->etag = $etag;
        }
        if ($close_fh) { fclose($fp); }
        return True;
    }
function write ( $ data = NULL , $ bytes = 0 , $ verify = True ) { if ( ! $ data ) { throw new SyntaxException ( "Missing data source." ) ; } if ( $ bytes > MAX_OBJECT_SIZE ) { throw new SyntaxException ( "Bytes exceeds maximum object size." ) ; } if ( $ verify ) { if ( ! $ this -> _etag_override ) { $ this -> etag = $ this -> compute_md5sum ( $ data ) ; } } else { $ this -> etag = NULL ; } $ close_fh = False ; if ( ! is_resource ( $ data ) ) { # A hack to treat string data as a file handle.  php://memory feels # like a better option, but it seems to break on Windows so use # a temporary file instead. # $ fp = fopen ( "php://temp" , "wb+" ) ; #$fp = fopen("php://memory", "wb+"); fwrite ( $ fp , $ data , strlen ( $ data ) ) ; rewind ( $ fp ) ; $ close_fh = True ; $ this -> content_length = ( float ) strlen ( $ data ) ; if ( $ this -> content_length > MAX_OBJECT_SIZE ) { throw new SyntaxException ( "Data exceeds maximum object size" ) ; } $ ct_data = substr ( $ data , 0 , 64 ) ; } else { $ this -> content_length = $ bytes ; $ fp = $ data ; $ ct_data = fread ( $ data , 64 ) ; rewind ( $ data ) ; } $ this -> _guess_content_type ( $ ct_data ) ; list ( $ status , $ reason , $ etag ) = $ this -> container -> cfs_http -> put_object ( $ this , $ fp ) ; #if ($status == 401 && $this->_re_auth()) { #    return $this->write($data, $bytes, $verify); #} if ( $ status == 412 ) { if ( $ close_fh ) { fclose ( $ fp ) ; } throw new SyntaxException ( "Missing Content-Type header" ) ; } if ( $ status == 422 ) { if ( $ close_fh ) { fclose ( $ fp ) ; } throw new MisMatchedChecksumException ( "Supplied and computed checksums do not match." ) ; } if ( $ status != 201 ) { if ( $ close_fh ) { fclose ( $ fp ) ; } throw new InvalidResponseException ( "Invalid response (" . $ status . "): " . $ this -> container -> cfs_http -> get_error ( ) ) ; } if ( ! $ verify ) { $ this -> etag = $ etag ; } if ( $ close_fh ) { fclose ( $ fp ) ; } return True ; }
Upload Object's data to Cloud Files

Write data to the remote Object.  The $data argument can either be a
PHP resource open for reading (see PHP's fopen() method) or an in-memory
variable.  If passing in a PHP resource, you must also include the $bytes
parameter.

Example:
<code>
# ... authentication/connection/container code excluded
# ... see previous examples

$my_docs = $conn->get_container("documents");
$doc = $my_docs->get_object("README");

# Upload placeholder text in my README
#
$doc->write("This is just placeholder text for now...");
</code>

@param string|resource $data string or open resource
@param float $bytes amount of data to upload (required for resources)
@param boolean $verify generate, send, and compare MD5 checksums
@return boolean <kbd>True</kbd> when data uploaded successfully
@throws SyntaxException missing required parameters
@throws BadContentTypeException if no Content-Type was/could be set
@throws MisMatchedChecksumException $verify is set and checksums unequal
@throws InvalidResponseException unexpected response
Upload Object s data to Cloud Files