Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions

Extend Upload



Optic Blaze

4 March 2014 at 4:03am Community Member, 162 Posts

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:

// 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;