We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25576
    • 27 Posts
    I’d appreciate some help with the following: on this site - http://www.webvivantpress.com - I’m about to start offering downloads of free e-books. The files that people can download are in PDF and/or ePub format (depending on the book).

    I’d like to log which books are being downloaded and I can’t work out the best way of doing this. Ideally, the visitor would click on a link on the the individual book’s page, such as http://www.webvivantpress.com/ladycaine.html, and be taken to a download page. I could then put the logging code on the download page. That much is easy. But then I’d like the download to start automatically, rather than force people to click again. It’s that automatic downloading part that I can’t get my head around. If someone could point me in the right direction, I’d be grateful.
      • 3749
      • 24,544 Posts
      Interesting problem. The only thing I can think of is a snippet on the landing page that used something like the following (untested):

      <?php
      $bookURL = ’path_to_the_book_file’;

      // logging code here

      $modx->sendRedirect($modx->makeURL($bookURL));
      ?>

      The problem is that there’s really no way to know if the user then actually downloads the book or aborts the download. And search bots (and spam bots) are going to follow that link and trigger the snippet without doing the download.

      There must be some way of doing it or none of the pay-to-download sites would work.

      You might look at using the FileDownload snippet: http://modxcms.com/extras/package/?package=146

      and the FileDownload Plugin: http://modxcms.com/extras/package/?package=148

      and putting your logging code in the plugin.

      I’ve never used the plugin, but it appears to detect aborted downloads.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 25576
        • 27 Posts
        Thanks for the info - I’ll look at the plug-in & snippet.

        It turns out that triggering the download is easy - a zero-sized iframe with the src= attribute pointing to the file does the job nicely. But it doesn’t address the problems you mentioned - aborted DLs and those triggered by bots.