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
Reply


14 Posts   4910 Views

Avatar
akshu

Community Member, 7 Posts

22 May 2010 at 1:11am

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

Avatar
Willr

Forum Moderator, 5513 Posts

22 May 2010 at 9:13pm

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

Avatar
akshu

Community Member, 7 Posts

25 May 2010 at 5:37pm

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

Avatar
Willr

Forum Moderator, 5513 Posts

25 May 2010 at 9:59pm

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.

Avatar
akshu

Community Member, 7 Posts

26 May 2010 at 7:01pm

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

Avatar
hi-tech

Community Member, 9 Posts

18 January 2011 at 9:20pm

Hello,

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>
   </div>

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

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

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??

Thx

Avatar
Invader_Zim

Community Member, 141 Posts

18 January 2011 at 10:28pm

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
</div>

Cheers,
Christian

Avatar
hi-tech

Community Member, 9 Posts

18 January 2011 at 10:34pm

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