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 | |
Definition at line 1667 of file cloudfiles-kt.php.
__construct | ( | & | $container, |
$name, | |||
$force_exists = False , |
|||
$dohead = True |
|||
) |
Class constructor
obj | $container | CF_Container instance |
string | $name | name of Object |
boolean | $force_exists | if set, throw an error if Object doesn't exist |
Definition at line 1686 of file cloudfiles-kt.php.
__toString | ( | ) |
String representation of Object
Pretty print the Object's location and name
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.
string | $handle | name of file or buffer to guess the type from |
True
if successful BadContentTypeException |
Definition at line 1748 of file cloudfiles-kt.php.
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.
filename | obj | string | $data | filename, open resource, or string |
Definition at line 2199 of file cloudfiles-kt.php.
getETag | ( | ) |
Object's MD5 checksum
Accessor method for reading Object's private ETag attribute.
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");
string | $filename | full path to local file |
boolean | $verify | enable local/remote MD5 checksum validation |
True
if data uploaded successfully SyntaxException | missing required parameters |
BadContentTypeException | if no Content-Type was/could be set |
MisMatchedChecksumException::$verify | is set and checksums unequal |
InvalidResponseException | unexpected response |
IOException | error opening file |
Definition at line 2103 of file cloudfiles-kt.php.
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.
array | $hdrs | user-defined headers (Range, If-Match, etc.) |
InvalidResponseException | unexpected 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");
string | $filename | name of local file to write data to |
True
if successful IOException | error opening file |
InvalidResponseException | unexpected response |
Definition at line 2147 of file cloudfiles-kt.php.
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.
string | $etag | MD5 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.
resource | $fp | open resource for writing data to |
array | $hdrs | user-defined headers (Range, If-Match, etc.) |
InvalidResponseException | unexpected response |
Definition at line 1878 of file cloudfiles-kt.php.
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();
True
if successful, False
otherwise InvalidResponseException | unexpected response |
Definition at line 1972 of file cloudfiles-kt.php.
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();
True
if successful, False
otherwise InvalidResponseException | unexpected response |
Definition at line 1929 of file cloudfiles-kt.php.
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...");
string | resource | $data | string or open resource |
float | $bytes | amount of data to upload (required for resources) |
boolean | $verify | generate, send, and compare MD5 checksums |
True
when data uploaded successfully SyntaxException | missing required parameters |
BadContentTypeException | if no Content-Type was/could be set |
MisMatchedChecksumException::$verify | is set and checksums unequal |
InvalidResponseException | unexpected response |
Definition at line 2007 of file cloudfiles-kt.php.
$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.