Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp.../includes/cloudfil...
File: cloudfiles.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* This is the PHP Cloud Files API.
[2] Fix | Delete
*
[3] Fix | Delete
* <code>
[4] Fix | Delete
* # Authenticate to Cloud Files. The default is to automatically try
[5] Fix | Delete
* # to re-authenticate if an authentication token expires.
[6] Fix | Delete
* #
[7] Fix | Delete
* # NOTE: Some versions of cURL include an outdated certificate authority (CA)
[8] Fix | Delete
* # file. This API ships with a newer version obtained directly from
[9] Fix | Delete
* # cURL's web site (http://curl.haxx.se). To use the newer CA bundle,
[10] Fix | Delete
* # call the CF_Authentication instance's 'ssl_use_cabundle()' method.
[11] Fix | Delete
* #
[12] Fix | Delete
* $auth = new CF_Authentication($username, $api_key);
[13] Fix | Delete
* # $auth->ssl_use_cabundle(); # bypass cURL's old CA bundle
[14] Fix | Delete
* $auth->authenticate();
[15] Fix | Delete
*
[16] Fix | Delete
* # Establish a connection to the storage system
[17] Fix | Delete
* #
[18] Fix | Delete
* # NOTE: Some versions of cURL include an outdated certificate authority (CA)
[19] Fix | Delete
* # file. This API ships with a newer version obtained directly from
[20] Fix | Delete
* # cURL's web site (http://curl.haxx.se). To use the newer CA bundle,
[21] Fix | Delete
* # call the CF_Connection instance's 'ssl_use_cabundle()' method.
[22] Fix | Delete
* #
[23] Fix | Delete
* $conn = new CF_Connection($auth);
[24] Fix | Delete
* # $conn->ssl_use_cabundle(); # bypass cURL's old CA bundle
[25] Fix | Delete
*
[26] Fix | Delete
* # Create a remote Container and storage Object
[27] Fix | Delete
* #
[28] Fix | Delete
* $images = $conn->create_container("photos");
[29] Fix | Delete
* $bday = $images->create_object("first_birthday.jpg");
[30] Fix | Delete
*
[31] Fix | Delete
* # Upload content from a local file by streaming it. Note that we use
[32] Fix | Delete
* # a "float" for the file size to overcome PHP's 32-bit integer limit for
[33] Fix | Delete
* # very large files.
[34] Fix | Delete
* #
[35] Fix | Delete
* $fname = "/home/user/photos/birthdays/birthday1.jpg"; # filename to upload
[36] Fix | Delete
* $size = (float) sprintf("%u", filesize($fname));
[37] Fix | Delete
* $fp = open($fname, "r");
[38] Fix | Delete
* $bday->write($fp, $size);
[39] Fix | Delete
*
[40] Fix | Delete
* # Or... use a convenience function instead
[41] Fix | Delete
* #
[42] Fix | Delete
* $bday->load_from_filename("/home/user/photos/birthdays/birthday1.jpg");
[43] Fix | Delete
*
[44] Fix | Delete
* # Now, publish the "photos" container to serve the images by CDN.
[45] Fix | Delete
* # Use the "$uri" value to put in your web pages or send the link in an
[46] Fix | Delete
* # email message, etc.
[47] Fix | Delete
* #
[48] Fix | Delete
* $uri = $images->make_public();
[49] Fix | Delete
*
[50] Fix | Delete
* # Or... print out the Object's public URI
[51] Fix | Delete
* #
[52] Fix | Delete
* print $bday->public_uri();
[53] Fix | Delete
* </code>
[54] Fix | Delete
*
[55] Fix | Delete
* See the included tests directory for additional sample code.
[56] Fix | Delete
*
[57] Fix | Delete
* Requres PHP 5.x (for Exceptions and OO syntax) and PHP's cURL module.
[58] Fix | Delete
*
[59] Fix | Delete
* It uses the supporting "cloudfiles_http.php" module for HTTP(s) support and
[60] Fix | Delete
* allows for connection re-use and streaming of content into/out of Cloud Files
[61] Fix | Delete
* via PHP's cURL module.
[62] Fix | Delete
*
[63] Fix | Delete
* See COPYING for license information.
[64] Fix | Delete
*
[65] Fix | Delete
* @author Eric "EJ" Johnson <ej@racklabs.com>
[66] Fix | Delete
* @copyright Copyright (c) 2008, Rackspace US, Inc.
[67] Fix | Delete
* @package php-cloudfiles
[68] Fix | Delete
*/
[69] Fix | Delete
[70] Fix | Delete
/**
[71] Fix | Delete
*/
[72] Fix | Delete
require_once(UPDRAFTPLUS_DIR."/includes/cloudfiles/cloudfiles_exceptions.php");
[73] Fix | Delete
require_once(UPDRAFTPLUS_DIR."/includes/cloudfiles/cloudfiles_http.php");
[74] Fix | Delete
@define("DEFAULT_CF_API_VERSION", 1);
[75] Fix | Delete
@define("MAX_CONTAINER_NAME_LEN", 256);
[76] Fix | Delete
@define("MAX_OBJECT_NAME_LEN", 1024);
[77] Fix | Delete
@define("MAX_OBJECT_SIZE", 5*1024*1024*1024+1);
[78] Fix | Delete
@define("US_AUTHURL", "https://auth.api.rackspacecloud.com");
[79] Fix | Delete
@define("UK_AUTHURL", "https://lon.auth.api.rackspacecloud.com");
[80] Fix | Delete
/**
[81] Fix | Delete
* Class for handling Cloud Files Authentication, call it's {@link authenticate()}
[82] Fix | Delete
* method to obtain authorized service urls and an authentication token.
[83] Fix | Delete
*
[84] Fix | Delete
* Example:
[85] Fix | Delete
* <code>
[86] Fix | Delete
* # Create the authentication instance
[87] Fix | Delete
* #
[88] Fix | Delete
* $auth = new CF_Authentication("username", "api_key");
[89] Fix | Delete
*
[90] Fix | Delete
* # NOTE: For UK Customers please specify your AuthURL Manually
[91] Fix | Delete
* # There is a Predfined constant to use EX:
[92] Fix | Delete
* #
[93] Fix | Delete
* # $auth = new CF_Authentication("username, "api_key", NULL, UK_AUTHURL);
[94] Fix | Delete
* # Using the UK_AUTHURL keyword will force the api to use the UK AuthUrl.
[95] Fix | Delete
* # rather then the US one. The NULL Is passed for legacy purposes and must
[96] Fix | Delete
* # be passed to function correctly.
[97] Fix | Delete
*
[98] Fix | Delete
* # NOTE: Some versions of cURL include an outdated certificate authority (CA)
[99] Fix | Delete
* # file. This API ships with a newer version obtained directly from
[100] Fix | Delete
* # cURL's web site (http://curl.haxx.se). To use the newer CA bundle,
[101] Fix | Delete
* # call the CF_Authentication instance's 'ssl_use_cabundle()' method.
[102] Fix | Delete
* #
[103] Fix | Delete
* # $auth->ssl_use_cabundle(); # bypass cURL's old CA bundle
[104] Fix | Delete
*
[105] Fix | Delete
* # Perform authentication request
[106] Fix | Delete
* #
[107] Fix | Delete
* $auth->authenticate();
[108] Fix | Delete
* </code>
[109] Fix | Delete
*
[110] Fix | Delete
* @package php-cloudfiles
[111] Fix | Delete
*/
[112] Fix | Delete
class UpdraftPlus_CF_Authentication
[113] Fix | Delete
{
[114] Fix | Delete
public $dbug;
[115] Fix | Delete
public $username;
[116] Fix | Delete
public $api_key;
[117] Fix | Delete
public $auth_host;
[118] Fix | Delete
public $account;
[119] Fix | Delete
[120] Fix | Delete
/**
[121] Fix | Delete
* Instance variables that are set after successful authentication
[122] Fix | Delete
*/
[123] Fix | Delete
public $storage_url;
[124] Fix | Delete
public $cdnm_url;
[125] Fix | Delete
public $auth_token;
[126] Fix | Delete
[127] Fix | Delete
/**
[128] Fix | Delete
* Class constructor (PHP 5 syntax)
[129] Fix | Delete
*
[130] Fix | Delete
* @param string $username Mosso username
[131] Fix | Delete
* @param string $api_key Mosso API Access Key
[132] Fix | Delete
* @param string $account <i>Account name</i>
[133] Fix | Delete
* @param string $auth_host <i>Authentication service URI</i>
[134] Fix | Delete
*/
[135] Fix | Delete
function __construct($username=NULL, $api_key=NULL, $account=NULL, $auth_host=US_AUTHURL)
[136] Fix | Delete
{
[137] Fix | Delete
[138] Fix | Delete
$this->dbug = False;
[139] Fix | Delete
$this->username = $username;
[140] Fix | Delete
$this->api_key = $api_key;
[141] Fix | Delete
$this->account_name = $account;
[142] Fix | Delete
$this->auth_host = $auth_host;
[143] Fix | Delete
[144] Fix | Delete
$this->storage_url = NULL;
[145] Fix | Delete
$this->cdnm_url = NULL;
[146] Fix | Delete
$this->auth_token = NULL;
[147] Fix | Delete
[148] Fix | Delete
$this->cfs_http = new UpdraftPlus_CF_Http(DEFAULT_CF_API_VERSION);
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
/**
[152] Fix | Delete
* Use the Certificate Authority bundle included with this API
[153] Fix | Delete
*
[154] Fix | Delete
* Most versions of PHP with cURL support include an outdated Certificate
[155] Fix | Delete
* Authority (CA) bundle (the file that lists all valid certificate
[156] Fix | Delete
* signing authorities). The SSL certificates used by the Cloud Files
[157] Fix | Delete
* storage system are perfectly valid but have been created/signed by
[158] Fix | Delete
* a CA not listed in these outdated cURL distributions.
[159] Fix | Delete
*
[160] Fix | Delete
* As a work-around, we've included an updated CA bundle obtained
[161] Fix | Delete
* directly from cURL's web site (http://curl.haxx.se). You can direct
[162] Fix | Delete
* the API to use this CA bundle by calling this method prior to making
[163] Fix | Delete
* any remote calls. The best place to use this method is right after
[164] Fix | Delete
* the CF_Authentication instance has been instantiated.
[165] Fix | Delete
*
[166] Fix | Delete
* You can specify your own CA bundle by passing in the full pathname
[167] Fix | Delete
* to the bundle. You can use the included CA bundle by leaving the
[168] Fix | Delete
* argument blank.
[169] Fix | Delete
*
[170] Fix | Delete
* @param string $path Specify path to CA bundle (default to included)
[171] Fix | Delete
*/
[172] Fix | Delete
function ssl_use_cabundle($path=NULL)
[173] Fix | Delete
{
[174] Fix | Delete
$this->cfs_http->ssl_use_cabundle($path);
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
/**
[178] Fix | Delete
* Attempt to validate Username/API Access Key
[179] Fix | Delete
*
[180] Fix | Delete
* Attempts to validate credentials with the authentication service. It
[181] Fix | Delete
* either returns <kbd>True</kbd> or throws an Exception. Accepts a single
[182] Fix | Delete
* (optional) argument for the storage system API version.
[183] Fix | Delete
*
[184] Fix | Delete
* Example:
[185] Fix | Delete
* <code>
[186] Fix | Delete
* # Create the authentication instance
[187] Fix | Delete
* #
[188] Fix | Delete
* $auth = new CF_Authentication("username", "api_key");
[189] Fix | Delete
*
[190] Fix | Delete
* # Perform authentication request
[191] Fix | Delete
* #
[192] Fix | Delete
* $auth->authenticate();
[193] Fix | Delete
* </code>
[194] Fix | Delete
*
[195] Fix | Delete
* @param string $version API version for Auth service (optional)
[196] Fix | Delete
* @return boolean <kbd>True</kbd> if successfully authenticated
[197] Fix | Delete
* @throws AuthenticationException invalid credentials
[198] Fix | Delete
* @throws InvalidResponseException invalid response
[199] Fix | Delete
*/
[200] Fix | Delete
function authenticate($version=DEFAULT_CF_API_VERSION)
[201] Fix | Delete
{
[202] Fix | Delete
list($status,$reason,$surl,$curl,$atoken) =
[203] Fix | Delete
$this->cfs_http->authenticate($this->username, $this->api_key,
[204] Fix | Delete
$this->account_name, $this->auth_host);
[205] Fix | Delete
[206] Fix | Delete
if ($status == 401) {
[207] Fix | Delete
throw new AuthenticationException("Invalid username or access key.");
[208] Fix | Delete
}
[209] Fix | Delete
if ($status < 200 || $status > 299) {
[210] Fix | Delete
throw new InvalidResponseException(
[211] Fix | Delete
"Unexpected response (".$status."): ".$reason);
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
if (!($surl || $curl) || !$atoken) {
[215] Fix | Delete
throw new InvalidResponseException(
[216] Fix | Delete
"Expected headers missing from auth service.");
[217] Fix | Delete
}
[218] Fix | Delete
$this->storage_url = $surl;
[219] Fix | Delete
$this->cdnm_url = $curl;
[220] Fix | Delete
$this->auth_token = $atoken;
[221] Fix | Delete
return True;
[222] Fix | Delete
}
[223] Fix | Delete
/**
[224] Fix | Delete
* Use Cached Token and Storage URL's rather then grabbing from the Auth System
[225] Fix | Delete
*
[226] Fix | Delete
* Example:
[227] Fix | Delete
* <code>
[228] Fix | Delete
* #Create an Auth instance
[229] Fix | Delete
* $auth = new CF_Authentication();
[230] Fix | Delete
* #Pass Cached URL's and Token as Args
[231] Fix | Delete
* $auth->load_cached_credentials("auth_token", "storage_url", "cdn_management_url");
[232] Fix | Delete
* </code>
[233] Fix | Delete
*
[234] Fix | Delete
* @param string $auth_token A Cloud Files Auth Token (Required)
[235] Fix | Delete
* @param string $storage_url The Cloud Files Storage URL (Required)
[236] Fix | Delete
* @param string $cdnm_url CDN Management URL (Required)
[237] Fix | Delete
* @return boolean <kbd>True</kbd> if successful
[238] Fix | Delete
* @throws SyntaxException If any of the Required Arguments are missing
[239] Fix | Delete
*/
[240] Fix | Delete
function load_cached_credentials($auth_token, $storage_url, $cdnm_url)
[241] Fix | Delete
{
[242] Fix | Delete
if(!$storage_url || !$cdnm_url)
[243] Fix | Delete
{
[244] Fix | Delete
throw new SyntaxException("Missing Required Interface URL's!");
[245] Fix | Delete
return False;
[246] Fix | Delete
}
[247] Fix | Delete
if(!$auth_token)
[248] Fix | Delete
{
[249] Fix | Delete
throw new SyntaxException("Missing Auth Token!");
[250] Fix | Delete
return False;
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
$this->storage_url = $storage_url;
[254] Fix | Delete
$this->cdnm_url = $cdnm_url;
[255] Fix | Delete
$this->auth_token = $auth_token;
[256] Fix | Delete
return True;
[257] Fix | Delete
}
[258] Fix | Delete
/**
[259] Fix | Delete
* Grab Cloud Files info to be Cached for later use with the load_cached_credentials method.
[260] Fix | Delete
*
[261] Fix | Delete
* Example:
[262] Fix | Delete
* <code>
[263] Fix | Delete
* #Create an Auth instance
[264] Fix | Delete
* $auth = new CF_Authentication("UserName","API_Key");
[265] Fix | Delete
* $auth->authenticate();
[266] Fix | Delete
* $array = $auth->export_credentials();
[267] Fix | Delete
* </code>
[268] Fix | Delete
*
[269] Fix | Delete
* @return array of url's and an auth token.
[270] Fix | Delete
*/
[271] Fix | Delete
function export_credentials()
[272] Fix | Delete
{
[273] Fix | Delete
$arr = array();
[274] Fix | Delete
$arr['storage_url'] = $this->storage_url;
[275] Fix | Delete
$arr['cdnm_url'] = $this->cdnm_url;
[276] Fix | Delete
$arr['auth_token'] = $this->auth_token;
[277] Fix | Delete
[278] Fix | Delete
return $arr;
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
[282] Fix | Delete
/**
[283] Fix | Delete
* Make sure the CF_Authentication instance has authenticated.
[284] Fix | Delete
*
[285] Fix | Delete
* Ensures that the instance variables necessary to communicate with
[286] Fix | Delete
* Cloud Files have been set from a previous authenticate() call.
[287] Fix | Delete
*
[288] Fix | Delete
* @return boolean <kbd>True</kbd> if successfully authenticated
[289] Fix | Delete
*/
[290] Fix | Delete
function authenticated()
[291] Fix | Delete
{
[292] Fix | Delete
if (!($this->storage_url || $this->cdnm_url) || !$this->auth_token) {
[293] Fix | Delete
return False;
[294] Fix | Delete
}
[295] Fix | Delete
return True;
[296] Fix | Delete
}
[297] Fix | Delete
[298] Fix | Delete
/**
[299] Fix | Delete
* Toggle debugging - set cURL verbose flag
[300] Fix | Delete
*/
[301] Fix | Delete
function setDebug($bool)
[302] Fix | Delete
{
[303] Fix | Delete
$this->dbug = $bool;
[304] Fix | Delete
$this->cfs_http->setDebug($bool);
[305] Fix | Delete
}
[306] Fix | Delete
}
[307] Fix | Delete
[308] Fix | Delete
/**
[309] Fix | Delete
* Class for establishing connections to the Cloud Files storage system.
[310] Fix | Delete
* Connection instances are used to communicate with the storage system at
[311] Fix | Delete
* the account level; listing and deleting Containers and returning Container
[312] Fix | Delete
* instances.
[313] Fix | Delete
*
[314] Fix | Delete
* Example:
[315] Fix | Delete
* <code>
[316] Fix | Delete
* # Create the authentication instance
[317] Fix | Delete
* #
[318] Fix | Delete
* $auth = new CF_Authentication("username", "api_key");
[319] Fix | Delete
*
[320] Fix | Delete
* # Perform authentication request
[321] Fix | Delete
* #
[322] Fix | Delete
* $auth->authenticate();
[323] Fix | Delete
*
[324] Fix | Delete
* # Create a connection to the storage/cdn system(s) and pass in the
[325] Fix | Delete
* # validated CF_Authentication instance.
[326] Fix | Delete
* #
[327] Fix | Delete
* $conn = new CF_Connection($auth);
[328] Fix | Delete
*
[329] Fix | Delete
* # NOTE: Some versions of cURL include an outdated certificate authority (CA)
[330] Fix | Delete
* # file. This API ships with a newer version obtained directly from
[331] Fix | Delete
* # cURL's web site (http://curl.haxx.se). To use the newer CA bundle,
[332] Fix | Delete
* # call the CF_Authentication instance's 'ssl_use_cabundle()' method.
[333] Fix | Delete
* #
[334] Fix | Delete
* # $conn->ssl_use_cabundle(); # bypass cURL's old CA bundle
[335] Fix | Delete
* </code>
[336] Fix | Delete
*
[337] Fix | Delete
* @package php-cloudfiles
[338] Fix | Delete
*/
[339] Fix | Delete
class UpdraftPlus_CF_Connection
[340] Fix | Delete
{
[341] Fix | Delete
public $dbug;
[342] Fix | Delete
public $cfs_http;
[343] Fix | Delete
public $cfs_auth;
[344] Fix | Delete
[345] Fix | Delete
/**
[346] Fix | Delete
* Pass in a previously authenticated CF_Authentication instance.
[347] Fix | Delete
*
[348] Fix | Delete
* Example:
[349] Fix | Delete
* <code>
[350] Fix | Delete
* # Create the authentication instance
[351] Fix | Delete
* #
[352] Fix | Delete
* $auth = new CF_Authentication("username", "api_key");
[353] Fix | Delete
*
[354] Fix | Delete
* # Perform authentication request
[355] Fix | Delete
* #
[356] Fix | Delete
* $auth->authenticate();
[357] Fix | Delete
*
[358] Fix | Delete
* # Create a connection to the storage/cdn system(s) and pass in the
[359] Fix | Delete
* # validated CF_Authentication instance.
[360] Fix | Delete
* #
[361] Fix | Delete
* $conn = new CF_Connection($auth);
[362] Fix | Delete
*
[363] Fix | Delete
* # If you are connecting via Rackspace servers and have access
[364] Fix | Delete
* # to the servicenet network you can set the $servicenet to True
[365] Fix | Delete
* # like this.
[366] Fix | Delete
*
[367] Fix | Delete
* $conn = new CF_Connection($auth, $servicenet=True);
[368] Fix | Delete
*
[369] Fix | Delete
* </code>
[370] Fix | Delete
*
[371] Fix | Delete
* If the environement variable RACKSPACE_SERVICENET is defined it will
[372] Fix | Delete
* force to connect via the servicenet.
[373] Fix | Delete
*
[374] Fix | Delete
* @param obj $cfs_auth previously authenticated CF_Authentication instance
[375] Fix | Delete
* @param boolean $servicenet enable/disable access via Rackspace servicenet.
[376] Fix | Delete
* @throws AuthenticationException not authenticated
[377] Fix | Delete
*/
[378] Fix | Delete
function __construct($cfs_auth, $servicenet=False)
[379] Fix | Delete
{
[380] Fix | Delete
if (isset($_ENV['RACKSPACE_SERVICENET']))
[381] Fix | Delete
$servicenet=True;
[382] Fix | Delete
$this->cfs_http = new UpdraftPlus_CF_Http(DEFAULT_CF_API_VERSION);
[383] Fix | Delete
$this->cfs_auth = $cfs_auth;
[384] Fix | Delete
if (!$this->cfs_auth->authenticated()) {
[385] Fix | Delete
$e = "Need to pass in a previously authenticated ";
[386] Fix | Delete
$e .= "CF_Authentication instance.";
[387] Fix | Delete
throw new AuthenticationException($e);
[388] Fix | Delete
}
[389] Fix | Delete
$this->cfs_http->setCFAuth($this->cfs_auth, $servicenet=$servicenet);
[390] Fix | Delete
$this->dbug = False;
[391] Fix | Delete
}
[392] Fix | Delete
[393] Fix | Delete
/**
[394] Fix | Delete
* Toggle debugging of instance and back-end HTTP module
[395] Fix | Delete
*
[396] Fix | Delete
* @param boolean $bool enable/disable cURL debugging
[397] Fix | Delete
*/
[398] Fix | Delete
function setDebug($bool)
[399] Fix | Delete
{
[400] Fix | Delete
$this->dbug = (boolean) $bool;
[401] Fix | Delete
$this->cfs_http->setDebug($this->dbug);
[402] Fix | Delete
}
[403] Fix | Delete
[404] Fix | Delete
/**
[405] Fix | Delete
* Close a connection
[406] Fix | Delete
*
[407] Fix | Delete
* Example:
[408] Fix | Delete
* <code>
[409] Fix | Delete
*
[410] Fix | Delete
* $conn->close();
[411] Fix | Delete
*
[412] Fix | Delete
* </code>
[413] Fix | Delete
*
[414] Fix | Delete
* Will close all current cUrl active connections.
[415] Fix | Delete
*
[416] Fix | Delete
*/
[417] Fix | Delete
public function close()
[418] Fix | Delete
{
[419] Fix | Delete
$this->cfs_http->close();
[420] Fix | Delete
}
[421] Fix | Delete
[422] Fix | Delete
/**
[423] Fix | Delete
* Cloud Files account information
[424] Fix | Delete
*
[425] Fix | Delete
* Return an array of two floats (since PHP only supports 32-bit integers);
[426] Fix | Delete
* number of containers on the account and total bytes used for the account.
[427] Fix | Delete
*
[428] Fix | Delete
* Example:
[429] Fix | Delete
* <code>
[430] Fix | Delete
* # ... authentication code excluded (see previous examples) ...
[431] Fix | Delete
* #
[432] Fix | Delete
* $conn = new CF_Connection($auth);
[433] Fix | Delete
*
[434] Fix | Delete
* list($quantity, $bytes) = $conn->get_info();
[435] Fix | Delete
* print "Number of containers: " . $quantity . "\n";
[436] Fix | Delete
* print "Bytes stored in container: " . $bytes . "\n";
[437] Fix | Delete
* </code>
[438] Fix | Delete
*
[439] Fix | Delete
* @return array (number of containers, total bytes stored)
[440] Fix | Delete
* @throws InvalidResponseException unexpected response
[441] Fix | Delete
*/
[442] Fix | Delete
function get_info()
[443] Fix | Delete
{
[444] Fix | Delete
list($status, $reason, $container_count, $total_bytes) =
[445] Fix | Delete
$this->cfs_http->head_account();
[446] Fix | Delete
#if ($status == 401 && $this->_re_auth()) {
[447] Fix | Delete
# return $this->get_info();
[448] Fix | Delete
#}
[449] Fix | Delete
if ($status < 200 || $status > 299) {
[450] Fix | Delete
throw new InvalidResponseException(
[451] Fix | Delete
"Invalid response (".$status."): ".$this->cfs_http->get_error());
[452] Fix | Delete
}
[453] Fix | Delete
return array($container_count, $total_bytes);
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
/**
[457] Fix | Delete
* Create a Container
[458] Fix | Delete
*
[459] Fix | Delete
* Given a Container name, return a Container instance, creating a new
[460] Fix | Delete
* remote Container if it does not exit.
[461] Fix | Delete
*
[462] Fix | Delete
* Example:
[463] Fix | Delete
* <code>
[464] Fix | Delete
* # ... authentication code excluded (see previous examples) ...
[465] Fix | Delete
* #
[466] Fix | Delete
* $conn = new CF_Connection($auth);
[467] Fix | Delete
*
[468] Fix | Delete
* $images = $conn->create_container("my photos");
[469] Fix | Delete
* </code>
[470] Fix | Delete
*
[471] Fix | Delete
* @param string $container_name container name
[472] Fix | Delete
* @return CF_Container
[473] Fix | Delete
* @throws SyntaxException invalid name
[474] Fix | Delete
* @throws InvalidResponseException unexpected response
[475] Fix | Delete
*/
[476] Fix | Delete
function create_container($container_name=NULL)
[477] Fix | Delete
{
[478] Fix | Delete
if ($container_name != "0" and !isset($container_name))
[479] Fix | Delete
throw new SyntaxException("Container name not set.");
[480] Fix | Delete
[481] Fix | Delete
if (!isset($container_name) or $container_name == "")
[482] Fix | Delete
throw new SyntaxException("Container name not set.");
[483] Fix | Delete
[484] Fix | Delete
if (strpos($container_name, "/") !== False) {
[485] Fix | Delete
$r = "Container name '".$container_name;
[486] Fix | Delete
$r .= "' cannot contain a '/' character.";
[487] Fix | Delete
throw new SyntaxException($r);
[488] Fix | Delete
}
[489] Fix | Delete
if (strlen($container_name) > MAX_CONTAINER_NAME_LEN) {
[490] Fix | Delete
throw new SyntaxException(sprintf(
[491] Fix | Delete
"Container name exeeds %d bytes.",
[492] Fix | Delete
MAX_CONTAINER_NAME_LEN));
[493] Fix | Delete
}
[494] Fix | Delete
[495] Fix | Delete
$return_code = $this->cfs_http->create_container($container_name);
[496] Fix | Delete
if (!$return_code) {
[497] Fix | Delete
throw new InvalidResponseException("Invalid response ("
[498] Fix | Delete
. $return_code. "): " . $this->cfs_http->get_error());
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function