Last active
December 28, 2015 20:29
-
-
Save rgbkrk/7557637 to your computer and use it in GitHub Desktop.
Simple PHP-OpenCloud sample code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Let's enable error reporting on this page | |
error_reporting(E_ALL); | |
ini_set('display_errors', True); | |
// If using composer | |
require 'vendor/autoload.php'; | |
//// If using a zip, will have to register the OpenCloud namespace | |
// Define the path to the library | |
//$libraryPath = '/path/to/php-opencloud'; | |
// Include the autoloader | |
//require_once $libraryPath . '/Autoload.php'; | |
// Register the root OpenCloud namespace | |
//$classLoader = new SplClassLoader('OpenCloud', $libraryPath . '/lib'); | |
//$classLoader->register(); | |
//require_once "php-opencloud.php"; | |
use OpenCloud\Rackspace; | |
$mysecret = array( | |
'username' => 'dse.junk', | |
'apiKey' => 'XXXXXXXXXXXXXXXXXXXXXXXXX' # Get this from account settings | |
); | |
// establish our credentials | |
$connection = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, $mysecret); | |
$service = $connection->objectStoreService('cloudFiles', 'IAD'); | |
// Note: can also leave region out | |
//$service = $connection->objectStoreService('cloudFiles'); | |
$containerList = $service->listContainers(); | |
while ($container = $containerList->next()) { | |
print("<p>Container: $container->name </p>"); | |
} | |
// Create a container | |
//$container = $service->createContainer('stuff'); | |
// Get the container (shown as example in case container exists) | |
$container = $service->getContainer('stuff'); | |
print("<p>Container: $container->name </p>"); | |
// CDN enable the container | |
$container->enableCdn(); | |
// Get the CDN location | |
$cdn = $container->getCdn(); | |
$cdn_uri = $cdn->getCdnUri(); | |
print("<p> CDN URI: $cdn_uri </p>"); | |
// The basic building block of cloudfiles, an object | |
$obj = $container->uploadObject("test.txt", "That was fun"); | |
$obj = $container->getObject("test.txt"); | |
$public_url = $obj->getPublicUrl(); | |
$content = $obj->getContent(); | |
print("<a href='$public_url'>$content</a>"); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# System dependencies | |
sudo apt-get update -y | |
sudo apt-get install -y apache2 | |
sudo apt-get install -y mysql-server libapache2-mod-auth-mysql php5-mysql # Must do MySQL setup next | |
sudo apt-get install -y php5 libapache2-mod-php5 php5-mcrypt | |
sudo apt-get install -y curl wget git php5-curl | |
# Get composer, drops it locally into your current directory | |
curl -sS https://getcomposer.org/installer | php | |
php composer.phar require rackspace/php-opencloud:dev-master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample run of installing composer