Okay, I've figured something out that works for uploading files. Here are my files for anyone that's interested:
ArticlePage.php (mysite/code/)
<?php
/**
* 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:
ArticlePage.ss (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" /> $file_upload.Title</strong> ($file_upload.getSize)</a></p>
<p><a href="http://www.adobe.com/products/acrobat/readstep2.html">Download the free PDF viewier <em>Adobe Reader</em> here</a></p>
</div>
<% end_if %>
</div>
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 :)