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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

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

Uploading a pdf or some kind of non image file

Go to End

11 Posts   9494 Views


Community Member, 1 Post

11 March 2007 at 11:19pm


I've added two file fileds in cms to add some non image files. I've doing this twice:
$fields->addFieldToTab("Root.Content.Files", new FileField('File'));

but there is no 'upload' button and i'dont know what i'm doing wrong

$fields->addFieldToTab("Root.Content.Files", new FileIFrameField('File'));

and also there is no 'upload' button but is 'attach..' from uploaded files and i attached but cms interpreted me my pdf file like image, hmmm is this correct

please give me some advice how to upload non image files

and is there any method to upload multi files in cms (in content section - has_many?? )?

Design City

38 Posts

2 September 2007 at 12:09am

Hi Guys,

I'm looking at doing something similar to the above (at least I think it is - had a trouble understanding the above post...). The information on Tutorial 2 - Creating a Staff section seems to be exactly what I'm looking for - except instead of Images, upload and attach a PDF (or any file, really...)

From playing around with the files in that tutorial, it looks like:

class StaffPage extends Page {
	static $db = array(
	static $has_one = array(
      'Photo' => 'Image'

The 'Image' part is the bit that actually references the image upload box, changing this to anything else seems to remove the image upload box and functionality.

Is there a way to simply enable upload of other files or is that a complex task? If it is relatively easy (for someone with limited knowledge) to do, can someone point me in the right direction of where and/or how this might be accomplished? I can only but try :)

Design City

38 Posts

5 September 2007 at 4:34pm

Edited: 05/09/2007 4:38pm

Okay, I've figured something out that works for uploading files. Here are my files for anyone that's interested:

ArticlePage.php (mysite/code/)


 * Defines the ArticlePage page type
class ArticlePage extends Page {
	static $db = array(
		'Date' => 'Date'
	static $has_one = array(
      'file_upload' => 'File'

	static $icon = "mysite/images/treeicons/news";
	function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->addFieldToTab('Root.Content.Main', new CalendarDateField('Date'), 'Content');
		$fields->addFieldToTab("Root.Content.PDF", new FileIFrameField('file_upload', 'Upload and Attach Document'));
		return $fields;
class ArticlePage_Controller extends Page_Controller {


This creates a new tab in the CMS called "PDF" (as that's what the client will be uploading, but could be anything else) and gives you a box to upload a file or select one from the assets folder. It also provides a textbox for a caption.

I call it on my template page as follows: (mysite/templates/Layout/)

	<div id="extra">
<% if file_upload %>
		<div class="extra_box">
			<h2>Download PDF</h2>
			<p>This announcement is available to download as an $file_upload.FileType:</p>
			<p><a target="_blank" href="$file_upload.URL">
			<strong><img src="$file_upload.Icon" alt="$file_upload.FileType" />&nbsp;&nbsp;$file_upload.Title</strong> ($file_upload.getSize)</a></p>
			<p><a href="">Download the free PDF viewier <em>Adobe Reader</em> here</a></p>
<% end_if %>

The template checks to see if there is a file uploaded first, otherwise doesn't display anything. The following variables are used:

$file_upload.URL - displays the relative url
$file_upload.Icon - displays the icon for the file type (can be edited from /saphire/filesystem/File.php - about line 519)
$file_upload.FileType - displays the name for the file type (in this case "Adobe Acrobat file", editable in the same file as above)
$file_upload.getSize - displays the size of the file in a clean format ("32 KB, 1.3 MB" etc.)
$file_upload.Title - displays the filename

This is just a way I found out to do what I was looking for - if anyone has a better way or even the 'right' way, please let me know :)


Community Member, 8 Posts

28 March 2008 at 12:48am

Why this example is not in documentation?
Generally documentation of SilverStripe (mainly navigation way) is messy and very
difficult to use.


Community Member, 24 Posts

24 June 2008 at 7:33am

Edited: 24/06/2008 7:50am

I agree pga. We really need to see a regrouping on the documentation efforts for SilverStripe. Without a more involved community and stronger documentation, SS can never reach the levels of utilization that it deserves. It really worries me. While SS is about the best CMS on the market for many CMS needs (Drupal only does better in a choice few scenarios) it needs a refocussing of effort from the developers on documentation and really giving us the tools we need to find answers handily. IRC doesn't help a lot when you're on a different time zone, etc.

Perhaps I should also qualify this a bit further: we need a recipe collection for SS. We need to have a central repository of specific things that could be useful and get some real contribution going in that direction.

Design City

38 Posts

24 June 2008 at 1:15pm

Edited: 24/06/2008 1:17pm

Some good points here pga and ylon. If you have any specific ideas of how you would improve the current system, probably best you start a topic at, the developers group discussion. I'm sure the SS staff would be very happy for the input. Posting here under "Uploading a pdf or some kind of non image file" is probably not going to get noticed.

The reason the code snippet isn't in the documentation is because I'm not a developer and while I created a working example, I'm not sure if this is the 'correct' way to create a file upload box. Putting something up on the wiki that is half right could confuse more than help.



Forum Moderator, 5523 Posts

24 June 2008 at 4:54pm

DesignCity - example looks fine to me. If you make a wiki page with this example and a bit of a introduction, talk that would sure be helpful for users!

One of the great things about the new Comments is that if the documentation is wrong, or is not the best way of doing things people can leave those remarks.. we can always refactor and or delete the page / information.


Community Member, 34 Posts

17 July 2008 at 5:05am


I have a problem with files attachment. I've already added the "attach file" field, but now i don't know how can I send this file as a attach in the email.

Any ideas to solve this?

Best regards

Go to Top