Jump to:

3376 Posts in 1000 Topics by 713 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Setting an upload to folder

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

Page: 1 2
Go to End
Author Topic: 2358 Views
  • kevino
    Avatar
    Community Member
    30 Posts

    Setting an upload to folder Link to this post

    Can I specify where files are uploaded to?

    If I'm using a normal FileIFrameField or ImageField, can I specify a setting in my *Page.php where the file will be uploaded to "assets/Uploads/*page-name*" instead of just dumping everything in "assets/Uploads"?

    Would really help in terms of file organisation, and would allow me to turn off the Files and Images tab.

  • baba-papa
    Avatar
    Community Member
    279 Posts

    Re: Setting an upload to folder Link to this post

    The folder is the 6th parameter of the FileField.php constructor. FileIFrameField is a direct descent of FileField.

  • kevino
    Avatar
    Community Member
    30 Posts

    Re: Setting an upload to folder Link to this post

    Hm, I actually really don't know how to use what you're suggesting

    could I do something like this:

    new FileIFrameField( 'File1', 'Upload One', '','','','assets/Uploads/$title' ),

  • baba-papa
    Avatar
    Community Member
    279 Posts

    Re: Setting an upload to folder Link to this post

    Thats exactly what I was talking about.

  • kevino
    Avatar
    Community Member
    30 Posts

    Re: Setting an upload to folder Link to this post

    Cool. Many thanks

    my code peice was just a guess to be honest; will the "$title" work in this part of the code, as I've only ever used it in the ss templates.

    Cheers
    Kevin

  • kevino
    Avatar
    Community Member
    30 Posts

    Re: Setting an upload to folder Link to this post

    hm. I get an unexpexted ',' error when I try this.

    I've been trying to get an upload to specify to 'assets/Uploads/$URLsegment' - if that's feasible.

  • kevino
    Avatar
    Community Member
    30 Posts

    Re: Setting an upload to folder Link to this post

    I still can't get this to work.

    From what I can gather, the logical thing to do is this:

    $fields->addFieldToTab('Root.Content.Image', new ImageField('Image', 'Image', null, null, null, 'assets/News/$URLsegment'));

    works in my head, just not in practice..

    Anyone?

  • zenmonkey
    Avatar
    Community Member
    524 Posts

    Re: Setting an upload to folder Link to this post

    I don't know if just specifying a path will actually create the directory or if it will give it the right permissions.

    2358 Views
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.