HPCloud-PHP  1.2.0
PHP bindings for HPCloud and OpenStack services.
 All Classes Namespaces Files Functions Variables Pages
streams-tutorial-example.php
Go to the documentation of this file.
1 <?php
2 require_once __DIR__ . '/../src/HPCloud/Bootstrap.php';
3 
4 use \HPCloud\Bootstrap;
5 Bootstrap::useAutoloader();
6 Bootstrap::useStreamWrappers();
7 
8 $ini = parse_ini_file(getenv('HOME') . '/.hpcloud.ini');
9 $settings = array(
10  'account' => $ini['account'],
11  'key' => $ini['secret'],
12  'tenantid' => $ini['tenantId'],
13  'endpoint' => $ini['url'],
14 );
15 Bootstrap::setConfiguration($settings);
16 
17 // Create a new file and write it to the object store.
18 $newfile = fopen('swift://Example/my_file.txt', 'w');
19 fwrite($newfile, "Good Morning!");
20 fclose($newfile);
21 
22 // Check for an object:
23 if (file_exists('swift://Example/my_file.txt')) {
24  print "Found my_file.txt." . PHP_EOL;
25 }
26 
27 // Get an entire object at once:
28 $file = file_get_contents('swift://Example/my_file.txt');
29 print 'File: ' . $file . PHP_EOL;
30 
31 $cxt = stream_context_create(array(
32  'swift' => array(
33  'account' => $ini['account'],
34  'key' => $ini['secret'],
35  'tenantid' => $ini['tenantId'],
36  'endpoint' => $ini['url'],
37  ),
38 ));
39 
40 print file_get_contents('swift://Example/my_file.txt', FALSE, $cxt);
41