<?php

		// Upload images to CloudSpace
		use OpenCloud\Rackspace;
		require '/root/rackspace-tools/vendor/autoload.php';
		$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
		'username' => 'santiago.martin',
		'apiKey'   => 'f0a9eb5ac4f341e5be20b353db25faac'
		));
		$objectStoreService = $client->objectStoreService(null, 'IAD');

		date_default_timezone_set('UTC');
		$y = date(Y);
		$m = date(m);
		$folder = "$m-$y";
		$cpanel_user = get_current_user();

		try {
				$container = $objectStoreService->getContainer($cpanel_user);
		} catch (Guzzle\Http\Exception\BadResponseException $e) {
				if ($e->getResponse()->getStatusCode() === 404) {
				}
		}

		#Si no existe el contenedor, lo creo.
		if (! $container)
		{
				$container = $objectStoreService->createContainer($cpanel_user);
		}


		// Se suben los dos archivos
		$localFileName  = '/home/virgen01/public_html/test-rx/test.txt';
		$remoteFileName = 'test.txt';

		$handle = fopen($localFileName, 'r');
		$object = $container->uploadObject($folder.'/'.$remoteFileName, $handle);
		fclose($handle);
		
?>
