Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Get filename on file upload - but how?


Go to End


2 Posts   991 Views

Avatar
etkinss

Community Member, 2 Posts

28 March 2013 at 1:52am

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")....

Avatar
swaiba

Forum Moderator, 1899 Posts

2 April 2013 at 6:39am

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.