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
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
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
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>.
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
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.
ok i'll try.... but thanks for the info
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
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 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.*"