| AND OR | string words | *

file handling

|

download counter


this 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"



full source of download counter [ line 1 - 30 ] | download download counter

1    <?php
2   $download_dir 'downloads'// the folder where the files are stored ('.' if this script is in the same folder)
3   $counter_dir 'counters'// the folder where your counter files are stored
4   /*
5   Save this script as download.php
6   each file to download must have a .txt-file called like "filename.ext.txt" in the 'counters' folder -
7   call the counter e.g. like this: <? include("counters/filename.pdf.txt"); ?>
8   download the file [download.php?get=name_of_file]
9   */
10   $path $download_dir.'/'.$HTTP_GET_VARS['get'];
11   if(file_exists($path))
12   {
13       $file fopen($counter_dir.'/'.$HTTP_GET_VARS['get'].'.txt','r+');
14       $count fread($file,100);
15       fclose($file); // closes file
16       $count++;
17       $file fopen($counter_dir.'/'.$HTTP_GET_VARS['get'].'.txt','w'); // opens file again with 'w'-parameter
18       fwrite($file$count);
19       fclose($file);
20       $size filesize($path);
21       header('Content-Type: application/octet-stream');
22       header('Content-Disposition: attachment; filename='.$HTTP_GET_VARS['get']);
23       header('Content-Length: '.$size);
24       readfile($path);
25   }else{
26       echo "<font face=$textfont size=2>";
27       echo "<center><br><br>The file [<b>$get$extension</b>] is not available for download.<br>";
28       echo "Please contact the web administrator <a href='http://www.yoursite.com</a>here";
29   }
30   ?>



62 hits by 20 users in the last 30 minutes.