Not a Member Yet,
Click here to Register
How do you like the new design?
It's cool, great job
[tally: 70%] 70%
It's okay
[tally: 20%] 20%
Its OK but I liked the old layout better
[tally: 0%] 0%
Please bring the old one back
[tally: 10%] 10%

votes: 10

ID: 537
Viewed: 3024
Added: Jan 30, 2007
Version: 1.0
Snippet uploaded by: M2EDesigns
Written By: M2EDesigns
Demo: Sorry, no demo



User Rated at: 5 Stars5 Stars5 Stars5 Stars5 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

Simple script for anyone that needs to count how many times a certain file is downloaded, and don't have access to a MySQL database. This first page is where the link to the file will be. You can use javascript to make it a pop up, or as it is here, just a normal link to a page containing the download script.

<!---Head--->
<?php
/*
*
* Script Name: File Download Count Script
* File Name: index.php
*
* Code By: Motion 2 Emotion Designs Inc.
* Website: http://www.m2edesigns.com
*
* Description: Perfect for anyone that needs to count how many
* times a certain file is downloaded, and don't have access to
* a MySQL database. This first page is where the link to the
* file will be. You can use javascript to make it a pop up,
* or as it is here, just a normal link to a page containing
* the download script.
*
* See It In Action At: http://www.stoneddevilinc.com/?i=tm_home.php
*
*/
?>
<html>
<head>
<title>Download Count Test</title>
</head>
<body>
<h1>Download Script Test</h1>
<?php
/*
This is the first part, that is an HTML link to the download
script, named download.php. The d_id=0, tells the script which
file to download, and which file to increase in the count.
*/
?>
<a href="download.php?d_id=0">Click Here To Download</a>
<br>
<?php

/*
This is where the file that stores the count is loaded.
Change the name "count.txt" to a file the script can access
and write to on your server.
*/
$s_entry = file_get_contents("count.txt");

/*
This part of the script decodes the data from the flat file
and puts it in a new array called $the_count.
*/
$the_count = unserialize($s_entry);

/*
This part of the script displays the count for each item. It
can be put where needed as long as it comes after the
unserialize function. Just change the index of the array for
each different file.
*/
echo 'Downloaded: ' . $the_count[0] . ' times';

?>
</body>
</html>

<!---Body--->


 <?php
/*
*
* Script Name: File Download Count Script
* File Name: download.php
*
* Code By: Motion 2 Emotion Designs Inc.
* Website: http://www.m2edesigns.com
*
* Description: This is the file that does most of the work. This is
* what the other file links to. Read below to see what each part does.
*
* See It In Action At: http://www.stoneddevilinc.com/?i=tm_home.php
*
*/
?>
<html>
<head>
<title>Download Count Script</title>
</head>
<body>
<center><h1>Download Will Begin Shortly</h1></center><br><br>
<?php

/*
This is where you set the diffrent file names for the download script.
Just change the array, and add what you will. Remeber, whatever index
the download file link is in the array, is what you need to set in the
file that has the links to download
*/
$f_id= array('test.txt');

/*
Next we set the variables needed for the script to run. The first sets
$the_count as an array, and gets the download id sent through the link
and sets it to $d_id here in the download count script.
*/
$the_count= array(0);
$d_id = $_GET['d_id'];

/*
Here we get the contents from the flat file, and decode them so the
script can use them. You need to change "count.txt" to the name of
the writeable file you are using for this script to work.
*/
$s_entry = file_get_contents("count.txt");
$the_count = unserialize($s_entry);

/*
Here is where we actually increase the count of the download. We
+= 1 to $the_count array, and the $d_id variable tells the array
which one to increase the count on.
*/
$the_count[$d_id] += 1;

/*
Now we open the file that we store the count in so we can write
the updated count in it. Remeber to change this to the name of
the file you are using for this script!!
*/
$file = fopen("count.txt","w+");

/*
Here we serialize $the_count to make the array storable in a flat
text file. We then write it to the file, and close the file.
*/
$f_entry = serialize($the_count);
fwrite($file,$f_entry);
fclose($file);

/*
This would be pointless if the user doesn't actually get to
download the file. We first set the url to the $f_id array with
the $d_id telling us what file in the array to get. next we use a
meta refresh to reload the page to the file they need to download.
We also give them a link to click just in case the download doesn't
sstart on its own for some reason.
*/
$url = $f_id[$d_id];
echo '<meta http-equiv="refresh" content="5;url='.$url.'">';
echo 'If Download Does Not Start, <a href='.$url.'>Click Here</a>';

?>
</body>
</html>


No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2017 snippetlibrary.com All Rights Reserved. Conditions