Jump to:

22972 Posts in 11596 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » Expanding the Specialized File Type List

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

Page: 1
Go to End
Author Topic: 1563 Views
  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Expanding the Specialized File Type List Link to this post

    SilverStripe’s “Files & Images” gives images special treatment. When uploaded, they are identified in the database (in the File table) as being of class Image. This information is later used by the system in various ways, including allowing SetWidth and SetHeight to be called from template code on images even though those methods are not available on other file types.

    Recently, I encountered a situation where it was necessary to give PDF files special behavior. It was easy to create a class PDF (child of class File) where I could add the desired methods. However, in order to get the uploader code to realize that .pdf files should be marked as class PDF in table File, I needed to edit the core file sapphire/filesystem/Folder.php. Needless to say, it is undesirable to edit core files to make configuration changes like registering a file type.

    The thought came to adjust Folder.php so that it maintains an array of file extensions and associated class names (like array(‘PDF’=> array(‘pdf’), ‘Image’ => array(‘jpg’, ‘jpeg’, ‘gif’, ‘png)) which would be used to identify the appropriate class with which to tag newly uploaded files. File type registration would be done in _config.php files using a syntax something like: File::register_type('pdf', 'PDF').

    Does this should like a feature that would be helpful to the community?

    Trying to figure out if this would benefit everyone at large, making it worthwhile to submit a patch, or if we're the only ones that need this, so we such just live with editing the core file.

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: Expanding the Specialized File Type List Link to this post

    The PDF class mentioned above adds the ability to automatically generate a thumbnail of the PDF (think<a href="$pdfFile.URL"><img src="$pdfFile.Thumbnail.src" />Download $pdfFile.Title</a>).

  • robinp
    Avatar
    Community Member
    33 Posts

    Re: Expanding the Specialized File Type List Link to this post

    Hi Ben,

    Just search for "icons for .pdf's" and found this. I'm really quite interested in you code. Would you be able to post it to the forum ?

    Cheers

    Robin

  • robinp
    Avatar
    Community Member
    33 Posts

    Re: Expanding the Specialized File Type List Link to this post

    Hi Ben,

    Just discovered that the project that I need the make icons for .pdf files is going ahead. Just wondering if you could post you PDF class or maybe we could talk about you doing some work on my project as freelance project.

    Cheers

    Robin

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Expanding the Specialized File Type List Link to this post

    Ben, definitely worth a patch - I'd like to see this in Core.

  • stevanovich
    Avatar
    Community Member
    59 Posts

    Re: Expanding the Specialized File Type List Link to this post

    What happened to this. I need to find out about generating PDF thumbnails, but cannot see the hack for the folder.php can anyone enlighten me with the details of how to do this.

    1563 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.