forked from oktawave-code/php-ocsclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OCSClient.php
68 lines (50 loc) · 1.92 KB
/
OCSClient.php
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/*
* Copyright (C) 2014 Oktawave Sp. z o.o. - oktawave.com
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Example usages of OCS Client class.
*
* @author Rafał Lorenz <rlorenz@octivi.com>
*/
require_once __DIR__ . '/../ocs_init.php';
// Create new OSC Client instance for "somebucket" bucket
$OCSClient = new Oktawave_OCS_OCSClient('somebucket');
// Authenticate your OCS user
$OCSClient->authenticate('account:user', 'pa$$w0rd');
// Upload objects from given directory - recursively
$urls = $OCSClient->createObjectsFromDir(__DIR__ . '/data', 'data/nested', true);
// Upload objects from given directory - not recursively
$urls = $OCSClient->createObjectsFromDir(__DIR__ . '/data', 'data', false);
// Upload objects from paths
$paths = array(__DIR__ . '/data/test.txt' => 'data/test.txt');
$urls = $OCSClient->createObjectsFromPaths($paths);
// Copy object
$copyUrl = $OCSClient->copyObject('data/test.txt', 'data/copy/test.txt');
// Rename object
$newUrl = $OCSClient->renameObject('data/test.txt', 'test_renamed.txt');
// Upload single object
$url = $OCSClient->createObject(__DIR__ . '/data/test.txt', 'data/test.txt');
// Create empty directory
$url = $OCSClient->createDirectory('data/testdir');
// Download object
$fileContent = $OCSClient->downloadObject('data/test.txt');
// Save object to file
$filePath = $OCSClient->downloadObjectToFile('data/test.txt', __DIR__ . '/data/testDownloaded.txt');
// Check if object exists
$isExisting = $OCSClient->checkObject('data/test.txt');
// Delete object
$isDeleted = $OCSClient->deleteObject('data/test.txt');
// List all objects
$list = $OCSClient->listObjects();
var_dump($list);
// List objects from pseudo-directory
$list = $OCSClient->listObjects('data');
var_dump($list);
//usuwanie wszystkich obiektów
//foreach ($list as $object) {
// $OCSClient->deleteObject($object['name']);
//}