Solutions to count downloads from a file

Asked

Viewed 246 times

3

Suppose for this case the apache server and php language.

The Problem

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

I need to get regular information on the number of successfully of formulario.pdf and refresh the.php form page by stating this number.

Forms of implementation

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

  1. Periodically check the server logs for file downloads (if there is such a data and it is safe to do so) and store the value on a basis;

  2. Execution of an action in PHP/HTML5/javascript stops at each download, after the termination (or interruption for some reason) are registered one of the following status: 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 code-solution to the problem, but which of the above alternatives is the most recommended (there may be even another one) and in this case, one can use an example code to help in the explanation.

  • 3

    This article depicts exactly what you need and with step-by-step instructions for you to do it in PHP and Mysql: https://www.vivaolinux.com.br/artigo/Criando-um-contador-de-downloads-com-PHP-e-MySQL

  • 1

    It would be good an answer, not that the article is not good, but external links usually disappear over time and Sopt is eternal.

  • Thanks for the @Paulo tip, there is a good starting point for solution 2, but as Florida said it is good to build something here that is better to study and discuss. It is good to also see an example of solution 1 and compare the advantages and disadvantages of each.

1 answer

1

I believe it’s a little personal preference,

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

  • Would this table be powered by PHP/javascript download processing or apache logs? What would be its data source and how it would be fed?

  • I would work with a trigger through javascript and as soon as the download completed would make an ajax call to a PHP that would insert the information in a database such as mysql, postgresql or any other database. There is a jquery plugin called fileDownload that helps you identify when you finish

  • plugin link: https://github.com/johnculviner/jquery.fileDownload

Browser other questions tagged

You are not signed in. Login or sign up in order to post.