Jump to:

23454 Posts in 18904 Topics by 2877 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: 415 Views
  • etkinss
    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
    Forum Moderator
    1788 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.

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.