Jump to:

22976 Posts in 11620 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Get filename on file upload - but how?

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
Go to End
Author Topic: 346 Views
  • etkinss
    Avatar
    Community Member
    2 Posts

    Get filename on file upload - but how? Link to this post

    What i need to do is getting the file name on file upload. I need to get the file name while uploading, write it to a cookie and read the cookie if it is set before. help please...

    function NewsletterForm() {
    $nameOfTheFile = ??? how to get the file name? // i need a code like $nameOfTheFile = $_FILES["file"]["tmp_name"]; on php.

    return new Form($this, "NewsletterForm", new FieldSet(

    // List your fields here
    new FileField("ImageURL", "AddPicture"),
    new EmailField("Email", "Email")....

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Get filename on file upload - but how? Link to this post

    Welcome etkinss!

    You'll probably want to place this in the onAfterWrite of the File - DataObject. Is this a UserDefinedForm or your own?
    If it's your own then extend the Image class and then when you write DataObject with onAfterWrite you can set your cookie. Ofcourse You might be able to access and shift scope to that image in a different way than a cookie, it would be preferable.

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