Jump to:

23023 Posts in 11882 Topics by 2830 members

General Questions

SilverStripe Forums » General Questions » PDF Download link

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

Page: 1 2
Go to End
Author Topic: 4369 Views
  • akshu
    Avatar
    Community Member
    7 Posts

    PDF Download link Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: PDF Download link Link to this post

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

  • akshu
    Avatar
    Community Member
    7 Posts

    Re: PDF Download link Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: PDF Download link Link to this post

    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.

  • akshu
    Avatar
    Community Member
    7 Posts

    Re: PDF Download link Link to this post

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

  • hi-tech
    Avatar
    Community Member
    9 Posts

    Re: PDF Download link Link to this post

    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

  • Invader_Zim
    Avatar
    Community Member
    141 Posts

    Re: PDF Download link Link to this post

    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

  • hi-tech
    Avatar
    Community Member
    9 Posts

    Re: PDF Download link Link to this post

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

    4369 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.