* Accessor method for reading Object's private ETag attribute.
* @return string MD5 checksum hexidecimal string
* Compute the MD5 checksum
* Calculate the MD5 checksum on either a PHP resource or data. The argument
* may either be a local filename, open resource for reading, or a string.
* <b>WARNING:</b> if you are uploading a big file over a stream
* it could get very slow to compute the md5 you probably want to
* set the $verify parameter to False in the write() method and
* compute yourself the md5 before if you have it.
* @param filename|obj|string $data filename, open resource, or string
* @return string MD5 checksum hexidecimal string
function compute_md5sum(&$data)
if (function_exists("hash_init") && is_resource($data)) {
$buffer = fgets($data, 65536);
hash_update($ctx, $buffer);
$md5 = hash_final($ctx, false);
} elseif ((string)is_file($data)) {
* PRIVATE: fetch information about the remote Object if it exists
private function _initialize()
list($status, $reason, $etag, $last_modified, $content_type,
$content_length, $metadata, $manifest, $headers) =
$this->container->cfs_http->head_object($this);
#if ($status == 401 && $this->_re_auth()) {
# return $this->_initialize();
if ($status < 200 || $status > 299) {
throw new InvalidResponseException("Invalid response (".$status."): "
. $this->container->cfs_http->get_error());
$this->last_modified = $last_modified;
$this->content_type = $content_type;
$this->content_length = $content_length;
$this->metadata = $metadata;
$this->headers = $headers;
$this->manifest = $manifest;
* Generate a Temp Url for a object
* # ... authentication code excluded (see previous examples) ...
* $conn = new CF_Connection($auth);
* $container = $conn->get_container("foo");
* $obj = $container->get_object("foo");
* $tempurl = $obj->get_temp_url("shared_secret", "expire_time_in_seconds", "{HTTP_METHOD}"); (note: replace {HTTP_METHOD} with the request method: GET, POST, PUT, DELETE, etc.
public function get_temp_url($key, $expires, $method)
$url = $this->container->cfs_http->getStorageUrl() . '/' . $this->container->name . '/' . $this->name;
return $url . '?temp_url_sig=' . hash_hmac('sha1', strtoupper($method) .
"\n" . $expires . "\n" . parse_url($url, PHP_URL_PATH), $key) .
'&temp_url_expires=' . $expires;
* Generate hidden input for form post.
* @returns array Returns an associative array with form post input.
public function get_form_post_input($key, $expires, $redirect, $max_file_size=5368709120, $max_file_count=1)
$url = $this->container->cfs_http->getStorageUrl() . '/' . $this->container->name . '/' . $this->name;
$form_post = array('action' => $url, 'redirect' => $redirect, 'max_file_size' => $max_file_size, 'expires' => $expires, 'file' => $this->name);
$form_post['signature'] = hash_hmac('sha1', parse_url($url, PHP_URL_PATH) . "\n" . $redirect . "\n" . $max_file_size . "\n" . $max_file_count . "\n" . $expires, $key );
#private function _re_auth()
# $new_auth = new CF_Authentication(
# $this->cfs_auth->username,
# $this->cfs_auth->api_key,
# $this->cfs_auth->auth_host,
# $this->cfs_auth->account);
# $new_auth->authenticate();
# $this->container->cfs_auth = $new_auth;
# $this->container->cfs_http->setCFAuth($this->cfs_auth);
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* c-hanging-comment-ender-p: nil