PHPology is a collective of highly skilled, award winning, web gurus.
Contact Raj on 07985 467 213 or email [email protected]

Rackspace Cloud API

Yesterday I was told that we were using the Rackspace Cloud server to store our files rather than on the local server itself.

At first I was like, this could be a pain in the ass as I was already storing the files locally, am i going to have to write some FTP code or something along the lines. NO!

The Rackspace Cloud API is actually pretty cool in what it does. Will take any file from a path defined locally and chuck it across into your BUCKET.

If you were to use the code that came with the example, its pretty messy to implement into your php page, as they quite a few line to add to your current page, so I wrote a class file, a simple class file, which allows you define your filename, your filepath and bam, your file is on the Cloud server.

Here is the glimpse of my example, of course you will need the Cloud classes also:


DEFINE("CLOUD_API", "asd123asd123asd123");
DEFINE("CLOUD_Username", "username");

$cs = new clsCloudServer(CLOUD_API, CLOUD_Username);
$response1 = $cs->upload_to_cloud("raj.jpg", "../assets/cloud/raj.jpg");
$response2 = $cs->upload_to_cloud("raj2.jpg", "../assets/cloud/raj2.jpg");
For me the benefit of doing this was so that I did not have to duplicate the default Cloud code example to upload 2/3 files at the same time. I just have to recall the $cs->upload_to_cloud() function and define the new file to move across. As you see above.

Download my example and hopefully its easy to understand and use!

I do plan to do add more functionality, such as deleting objects from the Cloud and so on, but at the moment, time is something I dont have. Feel free to add in yourself though.