As you can see, on this download page, I have placed images of the 6 editions of my e-magazine and have connected download buttons for each edition, so that whenever an user clicks on the download button, that particular file (.RAR file) will start downloading. Like I said, I have designed these buttons in plain HTML and CSS.
What I desire to have is DOWNLOAD COUNTERS for each magazine edition attached to the particualr DOWNLOAD BUTTONS -- meaning like you can see on my HTML page, the number of downloads to be written below each edition.How to have something like that? Can i have that arrangement with html?
I have another doubt : I had searched on Google for download counters and somewhere I had read that instead of directly giving the true path of my magazine file in the href, one should give an alternative path through another php filei.e I have at present this HTML code for a download button with Download
You can then loop through the class using the .each() function. So for initialisation of the page; i.e. getting all the page content working; you need to loop through every button and make a post request to the PHP script; all that needs to be sent to the PHP script is the id of the download. This is done in Part 1 of the code below.
Part 2 is setting up the event listener for when a download occurs. Once again, by just putting an event listener on the whole class we can detect a click on any of them; and then identify which button it came from by accessing it's id. (Note: For simplicity's sake; make the id in the markup the same as the id in the database)
This then makes another post request to the php script; but supplies an additional parameter - "download". In reality, the value that corresponds to download doesn't actually matter; because this case is simple enough that the user is either downloading it or not. So in the PHP segment of the code (later below) we don't even check it's value; we just check that it exists.
Server Side is where the PHP takes over. All this needs to do in reality is to check whether 'download' is set, and echo back the number of downloads. (Obviously incrementing the number with the database if the 'download' parameter is set)
It also leaves a question as to the displaying of the download number; as without AJAX you will have to embed some PHP in the HTML mark-up inline. I hope I've edited this to make a bit more sense, and given you an overview of the other option! :)
With only HTML and CSS, tracking the downloads won't be possible. You'll need to rely on (ideally) a combination of PHP and some type of database to track this. One option is to pass the file to be downloaded through a PHP file, but if you'd rather avoid that you could also make the links trigger an ajax request increasing the counter by one each time the link is clicked as well.
As noted by @johnmadrak you cannot display the amount of times a page has been viewed, or a file has been downloaded without some sort of server-side scripting language emphasizing some sort of database. In some scenarios you may even be able to place the amount of times a file has been download via a text document and then load the contents through PHP. 781b155fdc