Hi there,
I am building some front end forms and the users need to upload files. What i need to to add a timestamp to each file name. So a file called apple.jpg should become 20140301-apple.jpg. As far as i can see i need to extend the Upload Object to do that.
I found on line 137 of the Upload Class, that if i change the way $file works (which is in the upload function) i can add my timestamp in by doing the following:
$filenamegenerator = date('Ymdhis')."-";
$file = $nameFilter->filter($filenamegenerator.$tmpFile['name']);
So now i want to extend the upload function.
So far i have the following:
_config.php
-------------------------------------------------
// Extend the controller
Controller::add_extension('Upload', 'MyUploadExtention');
MyUploadExtention .php
-------------------------------------------------
class MyUploadExtention extends Extension {
public function myload() {
function load() {
$filenamegenerator = date('Ymdhis')."-".rand(1,10000)."-";
$file = $nameFilter->filter($filenamegenerator.$tmpFile['name']);
}
$this->extend('alterload', this->load());
return $load;
}
}