I'm running the latest version of Cake 2, and using the Miles Johns
Uploader Plugin. Works great so far, though I don't feel confident I set it
up correctly. But that aside, let's move on.
In my Controller, when I either add or edit a row, I upload the users
selected file.
Here's just a snippet of the code I'm using in my controller:
App::import('Vendor', 'Uploader.Uploader');
$this->Uploader = new Uploader(array(
'name' => 'formatFileName', // Name of the function to use to
format filenames
'uploadDir' => '/files/'
));
$data = $this->Uploader->upload($this->data['Upload']['file']);
Now, in bootstrap.php, I have the following function:
function formatFileName($name, $field, $file) {
echo "hello";
return md5($name);
}
However, the filename of the uploaded file is always the original file name.
Again, I've loaded the plugin in bootstrap with the following code:
CakePlugin::load('Uploader');
I've created a upload table in the DB, baked a controller and model for it,
but I'm saving the filename, path, size, and so on to that table. Looks
like the following:
CREATE TABLE IF NOT EXISTS `uploads` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`qarequest_id` int(11) NOT NULL,
`name` varchar(200) NOT NULL,
`type` varchar(200) NOT NULL,
`size` int(11) NOT NULL,
`filesize` varchar(200) NOT NULL,
`ext` varchar(200) NOT NULL,
`group` varchar(200) NOT NULL,
`custom_name` int(11) NOT NULL,
`path` varchar(200) NOT NULL,
`uploaded` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=35 ;
Let me know if I need to supply any other information, thanks all!
James
--
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.