Monday, February 22, 2010

CakePHP & User Uploads

The first time i tackled this problem i did the obvious thing, and placed the uploaded files in the webroot folder inside of the app folder. However the key problem with this is that you lose the ability to quickly move the app folder around without fear. This is important for me, as sometimes i'm working with bargin basement hosting, so "cap depoly" isn't always an option. Leaving the quickest way to deploy to simply replace the entire app folder via FTP. (We all have to start somewhere!)

Thankfully cakes media views allow you to specify a folder anywhere on the webserver!

What i decided to do was to make a simple controller called media and route all of my USG images through it.



class MediaController extends AppController {
/**
 *
 * @var string
 * @access public
 */
var $name = 'Media';

var $uses = array();

/**
 * Index action.
 *
 * @access public
 */
function index( $file = null, $size = 's'  ) {

$this->view = 'Media';

$components = split('\.',$file);

$params = array(
'id'=> $components[0],
'name'=> $components[0],
'extension'=> $components[1],
'path' => ROOT . DS. 'media' . DS .'filter'. DS . $size .DS . 'transfer' . DS . 'gen' . DS
);


$this->set($params);

}

}


So the controller looks a little something like this in it's raw form. I'm using the Media plugin, hence the addition folder paths. The key thing to note is the 'Path' key/val pair in the $params array. Notice you can pass an absolute file path! so in theory you could even mount another drive, and serve your media from there, pretty awesome.

This way, i can use a url like this

example.com/media/filename.jpg/l


To get a large image, and

example.com/media/filename.jpg/s


And this to get a small image.

Quite handy!

Sunday, February 21, 2010

Its 2010, Time to blog

For one reason or another i haven't done any blogging in ages. While i was at MWC the other week i decided that i ought to change that. While i don't really have time to be airing my thoughts into the ether, i feel as if i really ought too.

I've had an online property called Russian Space Station since late 2001, If for history's sake alone, The show must go on!

Monday, February 15, 2010

MWC 2010

Is huge. While I have little to sell and even less to buy it's been
interesting so far, and a overal good experience. Sadly none of the
folks that I know personally are here. But this is a different type of
event than what I'm used to going to. I mainly went because the ticket
was free, when yo get a 700 euro ticket for free you don't really
complain. So thanks to the folks from vodaphone.

The scale of this thing is crazy, my legs are knackered and I've only
been here for an hour and a half.

Jonathan