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.

All other Modules /

Discuss all other Modules here.

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

Adding to $allowed_extensions


Go to End


8 Posts   1651 Views

Avatar
tbarho

Community Member, 41 Posts

23 March 2010 at 10:57am

Edited: 23/03/2010 10:58am

Is there a way to add this to file? I've tried using a DataObject decorator, and tried subclassing File (ie.

class MyFile extends file
{
    static $allowed_extensions = array('someNewExtension');
}

but neither of those seem to work. The only thing that seems to work is manually adding it to the core File class.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

23 March 2010 at 1:15pm

I'm pretty sure $allowed_extensions has to go on the DataObject that contains the File.

Avatar
tbarho

Community Member, 41 Posts

23 March 2010 at 3:53pm

So it would look something more like

class SomeDataObject extends DataObject
{
      static $has_many = array ('Files' => 'MyFile');

      static $allowed_extensions = array('pdf');
}

class MyFile extends File
{

}

?

Does that seem more right?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

23 March 2010 at 4:34pm

Yeah, that looks good.

Avatar
tbarho

Community Member, 41 Posts

23 March 2010 at 4:37pm

Haha, nope =) Throws an error with SWF Upload

Avatar
tbarho

Community Member, 41 Posts

23 March 2010 at 4:39pm

Only way I can get it to work is by adding 'psd' to the core File $allowed_extensions definition =(

Avatar
UncleCheese

Forum Moderator, 4102 Posts

23 March 2010 at 4:44pm

What are you trying to do? What was the error?

Avatar
tbarho

Community Member, 41 Posts

23 March 2010 at 4:54pm

Well, I finally got SWFUpload to upload Files that are attached to a DataObject, except I started running into an error when trying to upload PSD files, which will be the primary type I need to upload. SWFUpload is giving the generic 500 internal server error, so I started Googling around, and found that a common cause was max file size. I checked that, it was right, so I dug down and figured out that File does not accept PSD file types, so it was throwing an error, even though I set SWFUpload to accept those (which I'm now assuming only controls the select window on the client side).

So I found the File base class, and $allowed_extensions, added 'psd' to the end of the array, and now it works. I don't like that, because it's not very modular, and I'm having to change the core to make my module work, which is kind of yuck, so I've been trying to find a way to extend from the base class and add more $allowed_extensions, but nothing seems to work.