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.

General Questions /

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

Get filename on file upload - but how?


Reply


2 Posts   456 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, 1799 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.