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

File Upload/Attach default to last location


Go to End


4 Posts   1013 Views

Avatar
bfrawls

Community Member, 2 Posts

13 May 2017 at 7:43am

Is there way to get an upload field to default to the last location you used when attaching an existing file? We have a rather large file library, and on multiple page types we have to attach multiple items from within the same folder, but the folder varies from page to page. It would be nice if UploadFiled could be configured to start in the last folder you visited so I don't have to dig through all of the folders each time.

Is that possible?

Avatar
martimiz

Forum Moderator, 1391 Posts

15 May 2017 at 11:09pm

Out of the box I don't think you can make the UploadField 'remember' where it last looked, that would involve some custom coding with cookies I guess. But you can tell the UploadField which Folder to open first, by using setDisplayFolderName(). I usualy (dynamically) create a special folder for each Page or DataObject, for instance based on the URLSegment. So if your pages each have their own folder - and it doesn't really change - you could:

            $folderName = "<[generate a] foldername";
            $fields->addFieldsToTab('Root.Main', array(
                SortableUploadField::create('Images', _t('PFProjectItem.IMAGES', 'Images'))
                   ->setAllowedExtensions(array('png', 'jpg', 'jpeg', 'gif'))
                   ->setAllowedMaxFileNumber(10)
                   ->setFolderName($foldername)                 //<== tels the UploadField where to store images
                   ->setDisplayFolderName($foldername)    //<== tells the uploadfield in which existing folder to look first
            ));

Avatar
bfrawls

Community Member, 2 Posts

18 May 2017 at 12:57am

I thought about trying something like that, but we generally upload our files to the library ahead of time and then just attach them.

Avatar
martimiz

Forum Moderator, 1391 Posts

18 May 2017 at 4:28am

Ok that's all about the workflow flowing where it flows :)

I agree though - it would be nice if UploadField would just remember. Something to look into...