Question: I'm looking for a way to send a user a regular file (mp3s or pictures), and keeping count of how many times this file was accessed **without going through an HTML/PHP page**.

For example, the user will point his browser to bla.com/file.mp3 and start downloading it, while a server-side script will do something like saving data to a database.

Any idea where should I get started?

Thanks!

Answer: 
You will need to go through a php script, what you could do is rewrite the extensions you want to track, preferably at the folder level, to a php script which then does the calculations you need and serves the file to the user.

For Example:

If you want to track the /downloads/ folder you would create a rewrite on your webserver to rewrite all or just specific extensions to a php file we'll call proxy.php for this example.

An example uri would be proxy.php?file=file.mp3 the proxy.php script sanitizes the file parameter, checks if the user has permission to download if applicable, checks if the file exists, serves the file to the client and perform any operations needed on the backend like database updates etc..
You would need to scan log files. Regardless you most likely would want to store counters in a database?

There is a great solution in serving static files using PHP:

<https://tn123.org/mod_xsendfile/>