this downloader snippet will count downloads of files and helps to cloak the real address of the file downloaded.

call like "thisscript.php?get=thefile_to_download"

download counter” makes use of the built-in PHP functions file_exists( ), fopen( ), fread( ), fclose( ), fwrite( ), filesize( ), header( ) and readfile( ).

01 <?php
02 
03 // the folder where the files are stored ('.' if this script is in the same folder)
04 $download_dir = 'downloads';
05  
06 // the folder where your counter files are stored
07 $counter_dir = 'counters';
08  
09 // Save this script as download.php
10 // each file to download must have a .txt-file called
11 // like "filename.ext.txt" in the 'counters' folder.
12 // display the counter like this: include('counters/filename.pdf.txt');
13 // download the file [download.php?get=name_of_file]
14 
15 $path = $download_dir.'/'.$_GET['get'];
16  
17 if(file_exists($path))
18 {
19     $file = fopen($counter_dir.'/'.$_GET['get'].'.txt','r+');
20     $count = fread($file,100);
21     fclose($file); // closes file
22     $count++;
23     // opens file again with 'w'-parameter
24     $file = fopen($counter_dir.'/'.$_GET['get'].'.txt','w');
25     fwrite($file, $count);
26     fclose($file);
27  
28     $size = filesize($path);
29  
30     header('Content-Type: application/octet-stream');
31     header('Content-Disposition: attachment; filename='.$_GET['get']);
32     header('Content-Length: '.$size);
33  
34     readfile($path);
35     
36 }else{
37  
38     echo '
39     <p class="error">
40         The file [<strong>'.$get.$extension.'</strong>] is not available for download.<br />
41         Please contact the web administrator <a href="http://www.yoursite.com">here</a>
42     </p>';
43 }
44  
45  
46 ?>