Tuesday, February 21, 2012

CakePhp file upload plugin

After much, MUCH googling i found this awesome file upload plugin. It has a great thumbnail feature and some really good validation options.

https://github.com/josegonzalez/upload/tree/2.0

However I found out you cant randomize the file name. (There is an option to randomize the folder it store the file in). After a bit of hack and slash i managed to append a random string 'time()' to file name.

/app/Plugin/Upload/Model/Behavior/UploadBehavior.php

//Line 78
private $rand_str;

//Line 87(inside the setup function)
$this->rand_str =  time();
//End of the beforeSave function
$model->data[$model->alias][$field] = $this->rand_str."_".
$model->data[$model->alias][$field];

This will append the UNIX time stamp to the file you're uploading as well the file name stored in the table and all the thumbnails.

Monday, February 20, 2012

Cakephp & Smartyhost

I recently found out smartyhost.com.au doesn't play well with cake Sessions.

'Please verify that the current setting of session.save_path is correct'

A simple fix for this is to change the Sessions from php to cake


/app/config/core.php
 Configure::write('Session', array(
  'defaults' => 'cake'
 ));

This will force Cake to use the /app/tmp path for Sessions instead of the Session path defined in smartyhost servers.