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
how to track number of downloads for a file
Moderator: General Moderators
- andym01480
- Forum Contributor
- Posts: 390
- Joined: Wed Apr 19, 2006 5:01 pm
Re: how to track number of downloads for a file
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
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
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: how to track number of downloads for a file
Or, simpler method:
count.txt:
download.php:
Just link to "download.php", instead of "file.exe"
The file called "count.txt" contains the number of times the file has been downloaded.
count.txt:
Code: Select all
0Code: 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);
?>The file called "count.txt" contains the number of times the file has been downloaded.
- andym01480
- Forum Contributor
- Posts: 390
- Joined: Wed Apr 19, 2006 5:01 pm
Re: how to track number of downloads for a file
Simpler if only one file to download!
Re: how to track number of downloads for a file
but how can i know that user has successfully downloaded the file or not?