Page 1 of 1
how to track number of downloads for a file
Posted: Thu Feb 07, 2008 7:47 am
by eshban
hi,
i need some help , how can i track the downloaded files. The files are hosted on my server. I need some php code to track number of downloads per file.
thnaks
Re: how to track number of downloads for a file
Posted: Thu Feb 07, 2008 7:58 am
by andym01480
I swap direct links to the files with someothing like download.php?file=888
Then have a database table with columns for filename, file_id and no of downloads
The download.php script updates the number of downloads by 1 and then sends headers and readfile("filename")
Job done
Re: how to track number of downloads for a file
Posted: Thu Feb 07, 2008 10:54 am
by Jonah Bron
Or, simpler method:
count.txt:
download.php:
Code: Select all
<?php
$file_to_download = 'file.exe';
$count = file_get_contents('count.txt');
$count++;
fwrite(fopen('count.txt, 'w'), $count);
header('Location: '. $file_to_download);
?>
Just link to "download.php", instead of "file.exe"
The file called "count.txt" contains the number of times the file has been downloaded.
Re: how to track number of downloads for a file
Posted: Thu Feb 07, 2008 11:26 am
by andym01480
Simpler if only one file to download!
Re: how to track number of downloads for a file
Posted: Fri Feb 08, 2008 2:07 am
by eshban
but how can i know that user has successfully downloaded the file or not?