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.

General Questions /

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

Expanding the Specialized File Type List


Reply


6 Posts   1670 Views

Avatar
Ben Gribaudo

Community Member, 181 Posts

25 March 2009 at 9:30am

Edited: 25/03/2009 9:32am

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.

Avatar
Ben Gribaudo

Community Member, 181 Posts

25 March 2009 at 9:38am

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

Avatar
robinp

Community Member, 33 Posts

28 February 2010 at 11:01pm

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

Avatar
robinp

Community Member, 33 Posts

25 March 2010 at 2:14pm

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

Avatar
Hamish

Community Member, 712 Posts

25 March 2010 at 2:29pm

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

Avatar
stevanovich

Community Member, 60 Posts

13 December 2011 at 4:54am

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.