Created
November 20, 2013 22:48
-
-
Save chrisrasco/7572580 to your computer and use it in GitHub Desktop.
An example using php-opencloud 1.7 to upload a remote image to a Cloud Files container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'vendor/autoload.php'; | |
$username = '<YOUR USERNAME>'; | |
$api_key = '<YOUR API KEY>'; | |
$my_container = '<CONTAINER NAME>'; | |
$cf_region = '<CF REGION>'; | |
$authURL = 'https://identity.api.rackspacecloud.com/v2.0/'; | |
$credentials = array( | |
'username' => $username, | |
'apiKey' => $api_key, | |
); | |
$connection = new \OpenCloud\Rackspace($authURL, $credentials); | |
$service = $connection->objectStoreService('cloudFiles', $cf_region); | |
// Get our container | |
$container = $service->getContainer($my_container); | |
// The remote file we want to grab | |
$remote_file_url = 'http://www.example.com/path/to/object.ext'; | |
$parts = explode("/",$remote_file_url); | |
$remote_file_name = $parts[count($parts)-1]; | |
echo "Uploading ".$remote_file_name." from ".$remote_file_url; | |
$data = fopen($remote_file_url, 'r'); | |
$container->uploadObject($remote_file_name, $data, array( | |
'Author' => 'Author Name' | |
)); | |
echo "Iterating through our container<br />"; | |
printf("*** %s<br />", $container->name); | |
//$this_cont = $objstore->getContainer($container->name); | |
printf("* %s<br />", $container->getURL()); | |
printf("* Contains %d objects<br />", $container->getObjectCount()); | |
printf("* %d bytes used<br /><br />", $container->getBytesUsed()); | |
$files = $container->ObjectList(); | |
while($o = $files->Next()) | |
{ | |
printf("Object: %s<br /> size: %d<br /> type: %s<br /> modified: %s<br /><br />", $o->getName(), $o->getContentLength(), $o->getContentType(), $o->getLastModified()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can we upload normal uploaded file rather than read the external url file ?