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

Allowing exotic & new file types to be uploaded and managed


Go to End


2 Posts   1907 Views

Avatar
vwd

Community Member, 166 Posts

27 January 2014 at 3:03pm

Hi,

When I attempt to add a new file with an unknown/new extension (say *.xyz) upon completing the upload in the CMS, I get a "Forbidden" error in UploadField. (I've already allowed this extension in UploadField - $myUploadField->getValidator()->setAllowedExtensions(array('xyz'));

Interestingly, the file is uploaded despite the error and when I try to attach the file to my DataaObject (via "From Files", as it is already now in the Assets folder) I can successfully attach the file.

After a bit of digging around, I can see that I have to add the new file extension via

File::$allowed_extensions[] = 'xyz'; 

However, this array is private and so I get a Fatal error: Cannot access private property File::$allowed_extensions.

So how would I be able add a new file type without hacking the core?

I don't want the file to be served so I won't add it in assets/.htaccess - just want to be able to upload it and use it within the web app.

Thanks,
VWD

Avatar
(deleted)

Community Member, 473 Posts

27 January 2014 at 7:13pm

You need to use the config API to add it. Something like this in config.yml will do it:

File:
   allowed_extensions:
    - xyz