download counter
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 ?>
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 ?>
Permissions in this forum:
You cannot reply to topics in this forum
Fri Jul 22, 2011 1:37 pm by shyamsunder
» Thousands of Free PHP Scripts Recommended
Wed May 18, 2011 10:33 am by bizboy12
» PHP form validation problem?
Wed Jan 12, 2011 1:25 pm by simy202
» string wrap
Sat Aug 02, 2008 2:06 pm by scvinodkumar
» retrieving current date rows
Tue Jul 15, 2008 3:25 am by scvinodkumar
» number in words
Tue Apr 29, 2008 3:10 pm by scvinodkumar
» Simple PHP Form Field Generator
Fri Apr 25, 2008 12:28 pm by scvinodkumar
» PHP password generator
Fri Apr 18, 2008 7:24 pm by scvinodkumar
» PHP Script to Extract Email Address from any text
Fri Apr 18, 2008 7:18 pm by scvinodkumar