forked from stackforge/openstack-sdk-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreams-tutorial-example.php
More file actions
40 lines (32 loc) · 1.02 KB
/
Copy pathstreams-tutorial-example.php
File metadata and controls
40 lines (32 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use \OpenStack\Bootstrap;
Bootstrap::useStreamWrappers();
$ini = parse_ini_file(getenv('HOME') . '/.OpenStack.ini');
$settings = [
'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([
'swift' => [
'account' => $ini['account'],
'key' => $ini['secret'],
'tenantid' => $ini['tenantId'],
'endpoint' => $ini['url'],
],
]);
print file_get_contents('swift://Example/my_file.txt', FALSE, $cxt);