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

PDF Download link

Go to End

14 Posts   4801 Views


22 May 2010 at 1:11am Community Member, 7 Posts

hello to everyone....

i'm trying to make a download link for pdf file in my application... but
unable to get any thing productive yet. I'm uploading pdf file through admin panel and want user to
download them in front end...

please help


22 May 2010 at 9:13pm Forum Moderator, 5511 Posts

How have you setup the backend? Are you simply uploading in the file and images section or are you attaching to a page via a FileField.

If you have done the former and you want to include the file in a page you should select the link text in the content editor (well the text you want to link to the file) and click the link icon in the tinymce toolbar. You can then select the file you want to make the link too.

If you are going to do the FileField / relationship option (such as tutorial 2 shows you with attaching images) then you should have a has_one relationship setup then in the templates you can use $NameOfFileField to get the pdf file you have uploaded - you can then use any methods like Link, Title on that to get a download like eg <a href="$NameOfFileField.Link">$NameOfFileField.Title</a>.


25 May 2010 at 5:37pm Community Member, 7 Posts

Hello Willr

Sory for replying so late.
i'm using

$f->addFieldToTab( 'Root.Content.PdfFile', new FileIFrameField('PDF', 'Upload and Attach PDF') );
to enable admin to upload file and maintaining relation as

static $has_one = array( 'PDF' => 'File' );
i'm able to show pdf in front end using <a href="$PDF.Link" >$PDF.Title</a> but i want user to download them by simply clicking on that link ... Now when user click on the link it get open .... although user can download them by right clicking and then selecting "save as"
option, but i don't want that option..

and thanks for replying


25 May 2010 at 9:59pm Forum Moderator, 5511 Posts

I don't think you have much control over whether the browser opens it or downloads it. Some browsers will override all downloading of PDFs (like safari) so not sure you can override that, you *may* be able to send it some header to force it as a standard file rather than pdf but not sure.


26 May 2010 at 7:01pm Community Member, 7 Posts

ok i'll try.... but thanks for the info


18 January 2011 at 9:20pm Community Member, 9 Posts


I'm trying to do the FileField / relationship option and have the following:

static $has_one = array(
   'PDF' => 'File',
'Photo' => 'Image'

function getCMSFields() {
$fields = parent::getCMSFields();

$fields->addFieldToTab("Root.Content.Images", new ImageField('Photo'));
   $fields->addFieldToTab("Root.Content.Files", new FileIFrameField('PDF'));

The template:
<div id="PcFile">
      <a href="$PDF.URL">$PDF.Title</a>

Unfortunately, in the frontend there just appears a broken link:

<div id="PcFile">
      <a href="/assets/"> </a>

My file is showing up correctly in the backend and I finally want to offer the same link (with the icon of a .pdf/.doc) in the frontend.

What am I doing wrong??



18 January 2011 at 10:28pm Community Member, 141 Posts

Hi hi-tech,

try this in your template:

<div id="PcFile">
<a href="$PDF.Link">$PDF.Title</a> //<a href="$PDF.URL"> is wrong imho



18 January 2011 at 10:34pm Community Member, 9 Posts

Hi Invader,

I gave it a try and it leads to the same false result. The method "Link" leads so the following output: "/assets/" instead of "/assets/uploads/myfile.*"

Go to Top