Counting the file that has been downloaded

By admin at 16 July, 2008, 9:58 am

In former post related to the download, I have tried showing how can we let our files to get downloaded by clients. Now next thing is, you may also want to count the numbers of files that have been downloaded. So my main motive to place this post is to help you count you files that have been downloaded. You can embed (copy and paste) it in your code. I hope this code will be beneficial one. Check it out.

NOTE :: [Create counter.txt file and embed this code]

[source code]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
<?php 
 
##################################
#Copyright 2008, Jayesh Shrestha
#You may use, modify and distribute  
#this code as long as this copyright
# notice is preserved.
##################################
 
/* counter for file downloaded  */
 
//checking that you have created counter.txt file or not
 
 if(!file_exists('counter.txt')){
	 die("Please create counter.txt file first");
 }
 
$file = fopen("counter.txt","r+");
$count = fread($file,100);
fclose($file); // closes file
 
$count++;
 
$file = fopen('counter.txt','w'); // opens file again with 'w'-parameter
fwrite($file, $count);
fclose($file);	
 
?>

Spread the Words!




No comments yet.

Sorry, the comment form is closed at this time.