Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Download pdf file

    I'm trying to implement a feature that allows the customer to immediately download a free pdf document like a catalog or newsletter from a sidebox. I've created the sidebox, set up a clickable button that initiates the download, and set up a function in includes/functions/extra_functions to do the download. My download function is based on the code in includes/modules/pages/download/header_php.php. Everything appears to work except code following the call to my download function is not executed. The code that calls the download function is in the update method in an observer class. In my download function the call to zen_exit() in the pages/download/header_php.php original code was replaced with a return to get back to the update method, but the return never happens. Observing the comment at the end of the original code that "the script should end here and not attempt to display any template components", I'm concerned with what I have done, even though the download happens and the page is displayed properly following the download.

    So, how do I get the code following the call to my download function execute, why must the script end following the download in the original code, and are there any security issues involved in continuing the script after the call to my download function?

    Many thanks,
    Dave

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,948
    Plugin Contributions
    96

    Default Re: Download pdf file

    Why not just provide a link to the PDF?

  3. #3
    Join Date
    Jul 2012
    Posts
    16,817
    Plugin Contributions
    17

    Default Re: Download pdf file

    I think I can come up with one reason though not sure if this aspect has been considered. By controlling the download through code instead of a direct link, the clicks can be tracked. Otherwise, with just a link, I'm not sure that is possible other than by clicking on such a link from a search engine's page.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  4. #4
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,948
    Plugin Contributions
    96

    Default Re: Download pdf file

    mc12345678, I agree with your comments. I was attempting to get the OP to provide a bit of a description of the requirements for his implementation (which might or might not include the ability to track the download's "consumption").

  5. #5
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Re: Download pdf file

    First, I didn't want the customer's browser to open the file automatically as a direct link would do. The reasons for this are (1) I don't want the customer to leave the store, and (2) the file may be large and load slowly in the browser. I also don't want to provide the "right click the link to download" instruction. The customers visiting this site have had problems with that approach...been there before. So I want to force the "save as" dialog box, which requires modifying the headers. I could provide a link to php code that does that, but isn't that what I'm doing now? Besides, I like the idea that the download file directory is hidden from the customer in the original and my modified download code. Finally, regarding tracking the consumption of downloads, that's what the code following the download function call is doing. I'm recording download data (customer_id, datetime, filename, etc.) in the database. Now I could (and have) moved the recording before the download call, but would prefer to record the data after the download in case of an error. Maybe I'm being paranoid on this point!? So how do I get the function to return to the observer class? "Return" does not do it.

  6. #6
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,948
    Plugin Contributions
    96

    Default Re: Download pdf file

    The nature of what your code is doing (initiating a file download via header modification) means that the "normal" Zen Cart page-load should not be allowed (it'll die due to the "headers already started" in your function). That's why the zen_exit() call is present at the bottom of the download page's header_php.php file.

    If there are some clean-up tasks that your observer needs to do, then code your function to return ... but be sure that the zen_exit () call is then issued by the observer-level code.

  7. #7
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Re: Download pdf file

    Thanks lat9. I figured out that indeed the script needs to end in the download function or in the observer code since there's nothing left for the script to do once the download is complete. I don't want to change or update the served page and the browser already has the page since before the customer clicked the download button. But a "return" in the download function is not working for some reason. I'm going to investigate a bit more to see if the script even gets to the return statement and where the script stops. If I can't find out why, I'll live with recording the data before the call to the download function or possibly call a function at the end of the download function to do the recording. In any event, I'll end the process with a zen_exit. I'm much more comfortable with it since I understand why the script must exit.
    Dave

  8. #8
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Re: Download pdf file

    To close off this thread, I found out why I could not getthe download function to return to the observer class code. The download type was set to redirect, so the function was redirected. When I changed the download type to streaming, the function returned to the calling code. Thanks everybody for your help.
    Dave

 

 

Similar Threads

  1. Replies: 3
    Last Post: 19 Dec 2014, 01:16 PM
  2. No shipping with download PDF file?
    By mikeylikesyou in forum Built-in Shipping and Payment Modules
    Replies: 2
    Last Post: 26 Feb 2011, 07:14 AM
  3. Replies: 16
    Last Post: 22 Jun 2010, 01:33 PM
  4. PDF download
    By Abel1717 in forum General Questions
    Replies: 2
    Last Post: 9 Mar 2009, 06:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg