Skip to content

Instantly share code, notes, and snippets.

@ycombinator
Last active August 29, 2015 13:57
Show Gist options
  • Save ycombinator/9391794 to your computer and use it in GitHub Desktop.
Save ycombinator/9391794 to your computer and use it in GitHub Desktop.
Pseudo-folders within container
<?php
require 'vendor/autoload.php';
use OpenCloud\Rackspace;
use OpenCloud\ObjectStore\Resource\DataObject;
// Create a client object to communicate with various Rackspace Cloud services.
$client = new Rackspace(Rackspace::UK_IDENTITY_ENDPOINT, array(
'username' => '<YOUR RACKSPACE CLOUD USERNAME HERE>',
'apiKey' => '<YOUR RACKSPACE CLOUD API KEY HERE>'
));
$region = 'DFW';
$objectStoreService = $client->objectStoreService('cloudFiles', $region);
// Create a container.
$container = $objectStoreService->createContainer('images');
// Upload a file to the container. Note the nesting in the destination
// file name ($destFilename). This is what *simulates* a nested folder
// structure within the container.
$srcFilename = '/Users/me/Pictures/mugshot.png';
$destFilename = 'photos/personal/me.png';
$data = fopen($srcFilename, 'r+');
$object = $container->uploadObject($destFilename, $data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment