JeevanisM Posted July 15, 2019 Share Posted July 15, 2019 Hello, Please help me on the below issue. I am creating a school text book website, simply displaying the PDF files of books to download by the visitor. Here I have created a new single page for a chapter and added a PDF file to that page from Admin Dashboard. But in the front I am not able to get the File Download url link to that PDF using API / Page references. Steps I followed as below : 1. created a new fields item as PDFFILE 2. added this filed into the Page template for Book 3. uploaded the PDF file to that page in Admin page edit 4. Saved and tried to use the API reference to get the full URL to the PDF file. I used this below api to get the download PDF url but this code is not working. when I load the page in browser, it keeps loading and loading and on..... $string = $pagefile->httpUrl(); Is there any other options available ? I simply a need a download PDF button to the attached PDF to that page itself thank you Jeevan S Link to comment Share on other sites More sharing options...
androbey Posted July 15, 2019 Share Posted July 15, 2019 Hi @JeevanisM, did you declare $pagefile before the call of "httpUrl()"? Maybe there are even log entries which give more information. In general it depends on wether you set a specific format for that specific field (single element or array) how to get the URL of the file. Assuming that your file field is named "pdffile": Case 1 - Single element $pdfUrl = $page->PDFFILE->httpUrl(); Case 2 - Array You either have to loop through all files or e.g. to get the first file: $pdfUrl = $page->PDFFILE->first()->httpUrl(); You can check format settings on details tab of your field. Link to comment Share on other sites More sharing options...
JeevanisM Posted July 16, 2019 Author Share Posted July 16, 2019 23 hours ago, androbey said: did you declare $pagefile before the call of "httpUrl()"? Maybe there are even log entries which give more information. How do I do that ?? I just added your code $pdfUrl = $page->PDFFILE->httpUrl(); but the page is just loading and loading and keep loading. So how should I declare the $pagefile ? Link to comment Share on other sites More sharing options...
androbey Posted July 16, 2019 Share Posted July 16, 2019 I would suggest you to use the fantastic Tracy Debugger tool and try to find out whats going on. Maybe there is something else wrong. Does the page load normally if you comment those lines out where you are trying to get file URL? Link to comment Share on other sites More sharing options...
Gideon So Posted July 16, 2019 Share Posted July 16, 2019 Hi @JeevanisM, Try this: echo $page->pagefile->httpUrl; $page: the current page pagefile: the page file field httpUrl: the full url of the pagefile The whole statement means echo the full url of the pagefile in current page. Hope this helps. Gideon Link to comment Share on other sites More sharing options...
JeevanisM Posted July 16, 2019 Author Share Posted July 16, 2019 2 hours ago, androbey said: Maybe there is something else wrong. Does the page load normally if you comment those lines out where you are trying to get file URL? yes the page loads fine when I remove the code. I even updated the core to latest dev from the standard, thinking if thats an issue Link to comment Share on other sites More sharing options...
JeevanisM Posted July 16, 2019 Author Share Posted July 16, 2019 2 hours ago, Gideon So said: echo $page->pagefile->httpUrl; this doesnt return any values, meaning displays nothing. The page loads fine but no result for the code. I made sure the PDF file is attached in the page Link to comment Share on other sites More sharing options...
Gideon So Posted July 16, 2019 Share Posted July 16, 2019 Hi @JeevanisM, Let me see. You should have code like this: <a href="<?php echo $page->pagefile->httpUrl; ?>">Click here to download</a> The code above should output a link to download the file. Gideon Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now