Location: PHPKode > projects > php-opencloud > php-opencloud-master/samples/objectstore/filter.php
// (c)2012 Rackspace Hosting
// See COPYING for licensing information

 * This sample illustrates how to create a Swift/CloudFiles object
 * from a file using the file_get_contents() function. It uses its
 * own source code as the data!

namespace OpenCloud;

define('NUM_OBJECTS', 30); // the number of objects to create
define('CONTAINERNAME', 'OpenCloud-Sample-Container');

define('AUTHURL', 'https://identity.api.rackspacecloud.com/v2.0/');
define('TENANT', $_ENV['OS_TENANT_NAME']);
define('APIKEY', $_ENV['NOVA_API_KEY']);

// establish our credentials
$connection = new Rackspace(AUTHURL,
	array('username' => USERNAME,
		   'apiKey' => APIKEY));

// create a Cloud Files (ObjectStore) connection
$ostore = $connection->ObjectStore(/* uses defaults from above */);

// next, make a container named 'Sample'
printf("Creating container %s.\n", CONTAINERNAME);
$sample = $ostore->Container();

// create a bunch of objects
printf("\nCreating %d randomly-named objects:\n", NUM_OBJECTS);
for ($i=0; $i<=NUM_OBJECTS; $i++) {
    $obj = $sample->DataObject();
    $obj->name = sprintf('%d-object-%d', rand(0,9), rand(0,999));
    printf("  Created %s\n", $obj->name);

// list all the objects in the container
print("\nListing all objects whose name starts with '3-':\n");
$list = $sample->ObjectList(array('prefix'=>'3-'));
while($o = $list->Next()) {
	printf("  Object: %s size: %d type: %s\n",
	    $o->name, $o->bytes, $o->content_type);

// delete everything
print("\nDeleting all the objects:\n");
$list = $sample->ObjectList();
while($o = $list->Next()) {
    printf("  Deleting %s\n", $o->name);

// and delete the container
printf("\nAnd, finally, deleting the container %s.\n", CONTAINERNAME);

Return current item: php-opencloud