php – Solutions for accounting for file downloads

Question:

Suppose for this case the apache server and php language.

The problem

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

I need to get the periodic information of the number of successful downloads of formrio.pdf and update the form.php page informing this number.

Ways of implementation

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

  1. Periodically consult the server logs regarding file downloads (If this data exists and it is safe to do so) and store the value in a database;

  2. Execution of an action in PHP/HTML5/javascript for each download, after the completion (or interruption for some reason) one of the following statuses is registered: success for the downloaded download and failure otherwise. 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 alternatives above is the most recommended (there may even be another one) and in this case, an example code can be used to help with the explanation.

Answer:

I believe it's a bit of personal preference,

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

Scroll to Top
AllEscort