Jump to:

10928 Posts in 2612 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » Adding to $allowed_extensions

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1065 Views
  • tbarho
    Avatar
    Community Member
    41 Posts

    Adding to $allowed_extensions Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Adding to $allowed_extensions Link to this post

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

  • tbarho
    Avatar
    Community Member
    41 Posts

    Re: Adding to $allowed_extensions Link to this post

    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?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Adding to $allowed_extensions Link to this post

    Yeah, that looks good.

  • tbarho
    Avatar
    Community Member
    41 Posts

    Re: Adding to $allowed_extensions Link to this post

    Haha, nope =) Throws an error with SWF Upload

  • tbarho
    Avatar
    Community Member
    41 Posts

    Re: Adding to $allowed_extensions Link to this post

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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Adding to $allowed_extensions Link to this post

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

  • tbarho
    Avatar
    Community Member
    41 Posts

    Re: Adding to $allowed_extensions Link to this post

    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.

    1065 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.