Jump to:

23461 Posts in 18908 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Custom upload directory

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2
Go to End
Author Topic: 3558 Views
  • banal
    Community Member
    901 Posts

    Re: Custom upload directory Link to this post

    Hi Aaron

    Of course you're right. I didn't read your code very carefully and was under the impression that you use Folder::findOrMake($this->URLSegment) each time "onBeforeWrite" is being called. Sorry, maybe it's because of the lacking indentation ;)

    Changed my code in the previous example to use 'Folder' instead of 'File'.

    The onBeforeWrite function on the DataObject would simply ensure that the file is located in the designated folder (defined by it's "holder" Page).

  • Double-A-Ron
    Community Member
    604 Posts

    Re: Custom upload directory Link to this post

    Gotcha, cheers for that.

    Yeah, it's strange. Copies from Dreamweaver to forum code blocks maintain indents. But from PHPEd to forum code blocks, the look fine, but they lose the tabs when I submit.

    Cheers mate.

  • torleif2
    Community Member
    4 Posts

    Re: Custom upload directory Link to this post

    Custom upload folders are set by changing the ParentID of the file. The following code will save an image to the server, and set the folder name to 'Articles', then write it to the database:

    $ImageFile = new Image();
    $ImageFile->ParentID = Folder::findOrMake('Articles')->ID;

    (Note: there's a bug in SS 2.4.1 that makes loadUploadedImage() unusable. My image class is actually extends Image, with a overwritten loadUploadedImage function)

Page: 1 2
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.