You can use the open source php library PHP OpenStack SDK to upload files to your push zones. The following shows how you can use it with 5centsCDN.
- Add PHP OpenStack SDK in your project using Composer
- composer require php-opencloud/openstack
- Add Guzzle, PHP HTTP Client in your project
- composer require guzzlehttp/guzzle
- Download the OpenStack RC v3 file from the OpenStack tab of the corresponding push zone.
- Login to the OpenStack Horizon File Manager and from left menu, Identity > Users, copy the User ID
- From the OpenStack RC File copy the variables:
- OS_PROJECT_ID, OS_USERNAME, OS_PASSWORD
- Create the php file and copy paste the following OpenStack initialization code
'http://controller.5centscdn.com/v3/', 'region' => 'RegionOne', 'user' => [ 'id' => 'xxxxxxxxx', // Replace with User ID copied in Step 4 'password' => 'xxxxxxx', // Replace with OS_PASSWORD copied from RC File ], 'scope' => [ 'project' => [ 'id' => 'xxxxxxx', //Replace with OS_PROJECT_ID ] ] ]); $container = $openstack->objectStoreV1()->getContainer('xxxxxxx'); //Replace with OS_USERNAME
- After you can follow the instructions in the PHP OpenStack SDK Docs to upload the files
Sample Usage
/* list container properties */ $container->retrieve(); print_r($container); /* list objects */ foreach ($container->listObjects([], function ($o) { return $o->retrieve(); }) as $object) { print_r($object); } /* List Object Detail */ $object = $container->getObject('01.mp4'); $object->retrieve(); echo "{$object->name}t{$object->contentType}t{$object->contentLength}".PHP_EOL; /* Upload files <5GB */ $file = '/path/to/filename.ext';//Absolute path to the file $object = $container->createObject([ 'name' => 'raw/'.pathinfo($file, PATHINFO_BASENAME), 'stream' => new Stream(fopen($file, 'r')), ]); $object->retrieve(); print_r($object);