Solutions to count downloads from a file

3

Suppose for this case the apache server and php language.

The Problem

I have a file on my server (eg: formular.pdf ) and there is a page ( formular.php ) that has a button to download this file.

I need to get periodic information of the successful download number of form.pdf and update the form.php page by reporting this number.

Implementation methods

The question is which of the following forms is most recommended, taking into account ease of implementation and security:

  • Periodically check the server logs for file downloads (If this data exists and it is safe to do so) and store the value on a database;

  • Execution of an action in PHP / HTML5 / javascript for each download, after termination (or interruption for some reason) one of the following status is registered: success for download downloaded and failure to do so. The value would be stored in a database.

  • Remembering that in this case the answer is not necessarily a solution code for the problem, but which of the above is the most recommended (there may even be another) and in this case, you can use example code to help explanation.

        
    asked by anonymous 17.06.2016 / 16:14

    1 answer

    1

    I think it's a little personal preference,

    I would particularly prefer to create a table to store the information of these downloads, it would be much easier to take statistics or something.

        
    17.06.2016 / 22:50