Track download numbers

Hi,

Basically, I am planning to host photography e-books on my site and give them away for free.

I need a way to track these downloads and display the amount of downloads on my site, like one of those how many vistors widgets you see from time to time.

I will upload these to my server and display each e-book via a blog post site wide. So I would have about 100 blog posts in the end each with a e-book.

However, to encourage downloads I will also host ALL books in a zip file on one page. So if someone comes to my site they can just download all the files straight away.

Now, how would I track this? I will be adding files to the zip files constantly. I’m sure I could track the downloads for blog posts and display them quite easy but I was wondering if there was any software that could keep track of all blog post downloads and the zip files downloads and add them up and display them.

If someone where to download the zip file then that would be an extra (n) of books onto the total.

Anyway, i’m sure you know what I mean by now. Is there anything that can do this or do I need a custom php script or something?

Many thanks, sorry to go on :wink:

Hi

If you just let the user to download the file directly, you can’t track the count of download. So, all the downloads happens through this program. Here now you have to ability increment the counter and store the update tracking count to db.

If you want to track the count for each file, just include the increment for each file by checking the file name in if conditions and increment the same in a table against the file name. Just read how to interact with database tables through php code.

Table structure can be:
id - int - primary key
filename - varchar
count - int

I included a comment in that code asking him to write his own code to increment a variable and store in db. That is pretty simple.

The code supplied isn’t tracking anything. You would add the tracking code to the that script that serves up the file.

Easy is pretty subjective term. For some one who doesn’t know know PHP I would say not.

wow- many thanks!

Sorry my php knowledge is very poor but this code will track the number of downloads in the zip file and display them?

Would it be easy to combine this tracking with tracking of single downloads on single posts and add them up to display them on the website?

Thanks again, you have been loads of help :smiley:

You can achieve this through a custom code:

  1. When you give link to a zip file, instead of mention it’s name, do like below:
    <a href=‘downloadfile.php?filename=myfirstphotographybook.zip’>First Book.zip</a>

  2. When user click on that link, downloadfile.php will be executed. In this php file, you have to write the code for incrementing the counter and give the requested file as download. Below is how you can achieve that:

<?php
	
	//Content of downloadfile.php
	
	$strRequestedFileName = $_REQUEST['filename'];
	if (file_exists($strRequestedFileName)) {
		
		//Increment the counter - You may choose to store this counter in a filed in db
		
	    header('Content-Description: File Transfer');
	    header('Content-Type: application/zip');
	    header('Content-Disposition: attachment; filename='.basename($strRequestedFileName));
	    header('Content-Transfer-Encoding: binary');
	    header('Expires: 0');
	    header('Content-Length: ' . filesize($strRequestedFileName));
	    readfile($file);
	}
	
	
?>

I can use the GA tracking function pretty easy. That’s what I meant