From Authentication to Objects
<?php
//Includes the CloudFiles PHP API.. Ensure the API files are located in your Global includes folder or in the same directory
require('cloudfiles.php');
//Now lets create a new instance of the authentication Class.
$auth = new CF_Authentication('UsernameGoesHere','APIKeyGoesHere');
//Calling the Authenticate method returns a valid storage token and allows you to connect to the CloudFiles Platform.
$auth->authenticate();
//The Connection Class Allows us to connect to CloudFiles and make changes to containers; Create, Delete, Return existing containers.
$conn = new CF_Connection($auth);
//Lets go ahead and create container.
$cont = $conn->create_container('PutContainerNameHere');
//Now lets make a new Object
$obj = $cont->create_object('PutObjectNameHere');
//Now lets put some stuff into the Object =)
$obj->write('LetsPutSomeDataHere');
?>
© 2011-2013 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

8 Comments
useful sample
Object Write Question
That's a pretty vague example. What does the write method accept? A path to a file, array of paths?
re: write method
https://github.com/rackspace/php-cloudfiles
Write method docs
The first argument can be EITHER a string or a PHP resource (i.e., a file handle). There are two optional arguments: a length (in bytes) and a boolean flag which, if TRUE, tells the library to verify the write.
Comments would be much more
re: comments
how to test for object existence?
re: testing object existence
http://docs.rackspace.com/files/api/v1/cf-devguide/content/Retrieve_Object_Metadata-d1e2301.html
That function would return a 404 code if the object doesn't exist. I believe that would be the head_object() function in the PHP bindings.
Add new comment