PageRenderTime 52ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/samples/ObjectStore/copy-object.php

https://github.com/unarmedwombat/php-opencloud
PHP | 53 lines | 14 code | 8 blank | 31 comment | 0 complexity | 048fb7e7395679c8ca327f10bc950c20 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. /**
  3. * Copyright 2012-2014 Rackspace US, Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. //
  18. // Pre-requisites:
  19. // * Prior to running this script, you must setup the following environment variables:
  20. // * RAX_USERNAME: Your Rackspace Cloud Account Username, and
  21. // * RAX_API_KEY: Your Rackspace Cloud Account API Key
  22. // * There exists a container named 'logos' in your Object Store. Run
  23. // create-container.php if you need to create one first.
  24. // * The 'logos' container contains an object named 'php-elephant.jpg'. Run
  25. // upload-object.php if you need to create it first.
  26. //
  27. require __DIR__ . '/../../vendor/autoload.php';
  28. use OpenCloud\Rackspace;
  29. // 1. Instantiate a Rackspace client.
  30. $client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
  31. 'username' => getenv('RAX_USERNAME'),
  32. 'apiKey' => getenv('RAX_API_KEY')
  33. ));
  34. // 2. Obtain an Object Store service object from the client.
  35. $region = 'DFW';
  36. $objectStoreService = $client->objectStoreService(null, $region);
  37. // 3. Get container.
  38. $container = $objectStoreService->getContainer('logos');
  39. // 4. Get object.
  40. $objectName = 'php-elephant.jpg';
  41. $object = $container->getObject($objectName);
  42. // 5. Create another container for object's copy.
  43. $objectStoreService->createContainer('logos_copy');
  44. // 6. Copy object to another container.
  45. $object->copy('logos_copy/php.jpg');