ucloud storage php doc
 All Data Structures Namespaces Files Functions Variables
Public Member Functions | Data Fields
CF_Object Class Reference

Public Member Functions

 __construct (&$container, $name, $force_exists=False, $dohead=True)
 
 __toString ()
 
 _guess_content_type ($handle)
 
 read ($hdrs=array())
 
 stream (&$fp, $hdrs=array())
 
 sync_metadata ()
 
 sync_manifest ()
 
 write ($data=NULL, $bytes=0, $verify=True)
 
 load_from_filename ($filename, $verify=True)
 
 save_to_filename ($filename)
 
 set_etag ($etag)
 
 getETag ()
 
 compute_md5sum (&$data)
 

Data Fields

 $container
 
 $name
 
 $last_modified
 
 $content_type
 
 $content_length
 
 $metadata
 
 $headers
 
 $manifest
 

Detailed Description

Definition at line 1667 of file cloudfiles-kt.php.

Constructor & Destructor Documentation

__construct ( $container,
  $name,
  $force_exists = False,
  $dohead = True 
)

Class constructor

Parameters
obj$containerCF_Container instance
string$namename of Object
boolean$force_existsif set, throw an error if Object doesn't exist

Definition at line 1686 of file cloudfiles-kt.php.

Member Function Documentation

__toString ( )

String representation of Object

Pretty print the Object's location and name

Returns
string Object information

Definition at line 1721 of file cloudfiles-kt.php.

_guess_content_type (   $handle)

Internal check to get the proper mimetype.

This function would go over the available PHP methods to get the MIME type.

By default it will try to use the PHP fileinfo library which is available from PHP 5.3 or as an PECL extension (http://pecl.php.net/package/Fileinfo).

It will get the magic file by default from the system wide file which is usually available in /usr/share/magic on Unix or try to use the file specified in the source directory of the API (share directory).

if fileinfo is not available it will try to use the internal mime_content_type function.

Parameters
string$handlename of file or buffer to guess the type from
Returns
boolean True if successful
Exceptions
BadContentTypeException

Definition at line 1748 of file cloudfiles-kt.php.

Here is the caller graph for this function:

compute_md5sum ( $data)

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.

WARNING: 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.

Parameters
filename | obj | string$datafilename, open resource, or string
Returns
string MD5 checksum hexidecimal string

Definition at line 2199 of file cloudfiles-kt.php.

Here is the caller graph for this function:

getETag ( )

Object's MD5 checksum

Accessor method for reading Object's private ETag attribute.

Returns
string MD5 checksum hexidecimal string

Definition at line 2180 of file cloudfiles-kt.php.

load_from_filename (   $filename,
  $verify = True 
)

Upload Object data from local filename

This is a convenience function to upload the data from a local file. A True value for $verify will cause the method to compute the Object's MD5 checksum prior to uploading.

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

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

Upload my local README's content

$doc->load_from_filename("/home/ej/cloudfiles/readme");

Parameters
string$filenamefull path to local file
boolean$verifyenable local/remote MD5 checksum validation
Returns
boolean True if data uploaded successfully
Exceptions
SyntaxExceptionmissing required parameters
BadContentTypeExceptionif no Content-Type was/could be set
MisMatchedChecksumException::$verifyis set and checksums unequal
InvalidResponseExceptionunexpected response
IOExceptionerror opening file

Definition at line 2103 of file cloudfiles-kt.php.

Here is the call graph for this function:

read (   $hdrs = array())

Read the remote Object's data

Returns the Object's data. This is useful for smaller Objects such as images or office documents. Object's with larger content should use the stream() method below.

Pass in $hdrs array to set specific custom HTTP headers such as If-Match, If-None-Match, If-Modified-Since, Range, etc.

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

$my_docs = $conn->get_container("documents"); $doc = $my_docs->get_object("README"); $data = $doc->read(); # read image content into a string variable print $data;

Or see stream() below for a different example.

Parameters
array$hdrsuser-defined headers (Range, If-Match, etc.)
Returns
string Object's data
Exceptions
InvalidResponseExceptionunexpected response

Definition at line 1821 of file cloudfiles-kt.php.

save_to_filename (   $filename)

Save Object's data to local filename

Given a local filename, the Object's data will be written to the newly created file.

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

Whoops! I deleted my local README, let me download/save it

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

$doc->save_to_filename("/home/ej/cloudfiles/readme.restored");

Parameters
string$filenamename of local file to write data to
Returns
boolean True if successful
Exceptions
IOExceptionerror opening file
InvalidResponseExceptionunexpected response

Definition at line 2147 of file cloudfiles-kt.php.

Here is the call graph for this function:

set_etag (   $etag)

Set Object's MD5 checksum

Manually set the Object's ETag. Including the ETag is mandatory for Cloud Files to perform end-to-end verification. Omitting the ETag forces the user to handle any data integrity checks.

Parameters
string$etagMD5 checksum hexidecimal string

Definition at line 2167 of file cloudfiles-kt.php.

stream ( $fp,
  $hdrs = array() 
)

Streaming read of Object's data

Given an open PHP resource (see PHP's fopen() method), fetch the Object's data and write it to the open resource handle. This is useful for streaming an Object's content to the browser (videos, images) or for fetching content to a local file.

Pass in $hdrs array to set specific custom HTTP headers such as If-Match, If-None-Match, If-Modified-Since, Range, etc.

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

Assuming this is a web script to display the README to the user's browser:

<?php // grab README from storage system // $my_docs = $conn->get_container("documents"); $doc = $my_docs->get_object("README");

// Hand it back to user's browser with appropriate content-type // header("Content-Type: " . $doc->content_type); $output = fopen("php://output", "w"); $doc->stream($output); # stream object content to PHP's output buffer fclose($output); ?>

See read() above for a more simple example.

Parameters
resource$fpopen resource for writing data to
array$hdrsuser-defined headers (Range, If-Match, etc.)
Returns
string Object's data
Exceptions
InvalidResponseExceptionunexpected response

Definition at line 1878 of file cloudfiles-kt.php.

Here is the caller graph for this function:

sync_manifest ( )

Store new Object manifest

Write's an Object's manifest to the remote Object. This will overwrite an prior Object manifest.

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

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

Define new manifest for the object

$doc->manifest = "container/prefix";

Push the new manifest up to the storage system

$doc->sync_manifest();

Returns
boolean True if successful, False otherwise
Exceptions
InvalidResponseExceptionunexpected response

Definition at line 1972 of file cloudfiles-kt.php.

Here is the call graph for this function:

sync_metadata ( )

Store new Object metadata

Write's an Object's metadata to the remote Object. This will overwrite an prior Object metadata.

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

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

Define new metadata for the object

$doc->metadata = array( "Author" => "EJ", "Subject" => "How to use the PHP tests", "Version" => "1.2.2" );

Define additional headers for the object

$doc->headers = array( "Content-Disposition" => "attachment", );

Push the new metadata up to the storage system

$doc->sync_metadata();

Returns
boolean True if successful, False otherwise
Exceptions
InvalidResponseExceptionunexpected response

Definition at line 1929 of file cloudfiles-kt.php.

Here is the caller graph for this function:

write (   $data = NULL,
  $bytes = 0,
  $verify = 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: ... 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...");

Parameters
string | resource$datastring or open resource
float$bytesamount of data to upload (required for resources)
boolean$verifygenerate, send, and compare MD5 checksums
Returns
boolean True when data uploaded successfully
Exceptions
SyntaxExceptionmissing required parameters
BadContentTypeExceptionif no Content-Type was/could be set
MisMatchedChecksumException::$verifyis set and checksums unequal
InvalidResponseExceptionunexpected response

Definition at line 2007 of file cloudfiles-kt.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Field Documentation

$container

Definition at line 1669 of file cloudfiles-kt.php.

$content_length

Definition at line 1673 of file cloudfiles-kt.php.

$content_type

Definition at line 1672 of file cloudfiles-kt.php.

$headers

Definition at line 1675 of file cloudfiles-kt.php.

$last_modified

Definition at line 1671 of file cloudfiles-kt.php.

$manifest

Definition at line 1676 of file cloudfiles-kt.php.

$metadata

Definition at line 1674 of file cloudfiles-kt.php.

$name

Definition at line 1670 of file cloudfiles-kt.php.


The documentation for this class was generated from the following file: