• Sales: 1-800-961-2888
  • Support: 1-800-961-4454

Sample PHP Application


Simple Sample Application

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


See license specifics and DISCLAIMER

8 Comments

I just find you php api and I think that has all the necessary featuers with detailed documentation and samples. rackspace is far one of the best CDN

It would be good to know where I could read more about $obj->write('LetsPutSomeDataHere');
That's a pretty vague example. What does the write method accept? A path to a file, array of paths?

I'm afraid I can't answer that offhand, but the documentation for the PHP language bindings for Cloud Files is available in its github repo:
https://github.com/rackspace/php-cloudfiles

If you've downloaded the files, the documentation on this method is at docs/php-cloudfiles/CF_Object.html#methodwrite

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 useful if you stated what this code as a whole is supposed to accomplish.

are there any code samples illustrating how to test if an object exists in a container?

The simplest way would probably be with the "fetch object metadata" function:

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