Files
openstack-sdk-php/doc/streams-tutorial-example.php
Sam Choi e5c695f72a Partially implements blueprint psr-2
Change-Id: Ifd8b7237f650f0f18fa58ab0e870eb2774c776fc
2014-04-17 20:12:47 -07:00

42 lines
1.1 KiB
PHP

<?php
require_once __DIR__ . '/../src/OpenStack/Autoloader.php';
use \OpenStack\Autoloader;
use \OpenStack\Bootstrap;
Autoloader::useAutoloader();
Bootstrap::useStreamWrappers();
$ini = parse_ini_file(getenv('HOME') . '/.OpenStack.ini');
$settings = array(
'account' => $ini['account'],
'key' => $ini['secret'],
'tenantid' => $ini['tenantId'],
'endpoint' => $ini['url'],
);
Bootstrap::setConfiguration($settings);
// Create a new file and write it to the object store.
$newfile = fopen('swift://Example/my_file.txt', 'w');
fwrite($newfile, "Good Morning!");
fclose($newfile);
// Check for an object:
if (file_exists('swift://Example/my_file.txt')) {
print "Found my_file.txt." . PHP_EOL;
}
// Get an entire object at once:
$file = file_get_contents('swift://Example/my_file.txt');
print 'File: ' . $file . PHP_EOL;
$cxt = stream_context_create(array(
'swift' => array(
'account' => $ini['account'],
'key' => $ini['secret'],
'tenantid' => $ini['tenantId'],
'endpoint' => $ini['url'],
),
));
print file_get_contents('swift://Example/my_file.txt', FALSE, $cxt);