Jump to:

3450 Posts in 1063 Topics by 738 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Extend Upload

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 205 Views
  • Optic Blaze
    Community Member
    162 Posts

    Extend Upload Link to this post

    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;

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.