Skip to content
wishfoundry edited this page Oct 5, 2012 · 6 revisions

This is a Laravel Bundle for uploading and removing files from Rackspace CloudFiles.

Getting started

Installation

Install cloudfiles using artisan:

php artisan bundle:install cloudfiles

Then in your application/bundles.php file, add the following line to load Resizer automatically:

return array(
    'cloudfiles' => array( 'auto' => true )
);

Or without the 'auto' => true to load it on demand:

return array(
    'cloudfiles'
);

Basic Uploading Usage

<?php
Bundle::start('cloudfiles');
$cf = Ioc::resolve('cloudfiles');

/**
 * Set the container (Bucket for your AWS S3 fans)
**/
$container = $cf->get_container('my_demo_container');

/**
 * $new_files becomes the new object. Set the file name
 **/
$new_file = $container->create_object('my_image_file_name.jpg');

/**
 * Upload an existing file to the $new_file object. This part is actually uploading to the CDN
 **/
if (($saved_file = $new_file->load_from_filename('savedpics/my_image_file_name.jpg'))!== false) {
  // image uploaded. do some stuff here
} else {
  // error
  echo 'Error uploading my_image_file_name.jpg';
}

Basic Deletion Usage

<?php
Bundle::start('cloudfiles');
$cf = Ioc::resolve('cloudfiles');

/**
 * Set the container (Bucket for your AWS S3 fans)
**/
$container = $cf->get_container('my_demo_container');

/**
 * Delete the file by name from the container
 **/
if ($container->delete_object('my_image_file_name.jpg'))
	echo 'my_image_file_name.jpg has been deleted';
else
	echo 'Error deleting my_image_file_name.jpg';
Clone this wiki locally