File Submitter: Cris D.
File Submitted: 28 Oct 2007
File Updated: 1 Nov 2007
File Category: Miscellaneous
READ ME for Snippet: DownloadCounter
Version: Ver 1.3 (beta).
Author: Cris D.
Date: 2007/10/28
See in action here.
Credits: Etomised and secured from the original script found here.
And php's filesize_readable function from here.
DownloadCounter generates:
filename - download link - custom message number of downloads - filesize.
example:
image.jpg Download it Now This has been downloaded 23 times (36kB)
It also can be (optionally) used to stop unauthorized downloads by checking permissions of a user.
INSTALLATION INSTRUCTIONS:
For ease of installation, these instructions will describe how to set up this snippet with its default settings. However, most of these steps can be customised if the changes are reflected in the snippet if you know what you are doing.
1) Create a folder called downloads in the same folder as your index.php file (etomite root).
2) Inside that create a folder called counters.
You should now have two folders:
downloads
downloads/counters
CHMOD the counters folder to 755 if it is not already (this can be tightened up later if necessary but it must be readable and writable).
3) Using ftp or etomite's File Manager, place the files you want to be downloaded in the 'downloads' folder (take note of the name and extention).
4) Copy and paste the snippet into your snippet library, call it DownloadCounter.
5) Place the snippet in the page where you want the download link to show.
[indent]The snippet generates:
Scenario 1) ** IF BROWSER HAS ACCESS TO THE DOWNLOAD LINK**
"filename.ext: <a href>Download</a> This file has been downloaded [nn] times."
Scenario 2) ** IF SECURITY HAS BEEN SET AND USER IS NOT LOGGED IN**
"filename.ext You are not authorised to download: download2.txt
<a href>Contact the webmaster</a>."
Scenario 3) ** IF FILE DOES NOT EXIST OR THERE IS A PROBLEM LOCATING IT **
"download2.txt This link to downloads/filename.ext does not point to a valid file."[/indent]
6) Write the snippet call to a) Point the snippet to the particular file
[indent]6 a) Pointing the snippet to the file is done by adding
[!DownloadCounter?fileName=name_of_file.extention!]
6
[!DownloadCounter?fileName=name_of_file.extention&secure=true!]
6 c) Set the download_dir if the file is stored outside the downloads folder by adding
[!DownloadCounter?download_dir=assets/images&filename=cloud.jpg!]
[/indent]
So to set the download of a file called cat.jpg and make it secure, you would place
[!DownloadCounter?fileName=cat.jpg&secure=true!] in the page where you want the Senario 1 or 2 to appear.
#### OPTIONAL SNIPPET CONFIGURATION #########
The folder where the file is stored it can also be set in the snippet call to point to a different dir
eg [!DownloadCounter?download_dir=assets/images&fileName=cloud.jpg!]
$download_dir=isset($download_dir)? $download_dir : 'downloads'; //this is the default directory to look in- $counter_dir = 'downloads/counters'; // the folder where your counter files are stored (CHMOD to 755)
- Set whether the default is secure of not. (This can be overridden in the snippet call).
$secure=isset($secure)? $secure:false; - $deny=" You are not authorised to download: ";//message to set for output
- $redirectPage=58;//set to the id of the page where you can be contacted if you want to prompt users to 1) set up an account 2) get a membership 3) check thier log-in details etc
- Set a default file to download if not called in the snippet call (suggested of you are a lazy web housekeeper): It should stop the error message for file not found from showing. However, you will need to actually put that file there!
$fileName= isset($fileName) ? $fileName:'download1.txt'; - This will read
Quote
[indent]$DownloadMessage=" This has been downloaded ";$DownloadMessage [nn] $times.
$times=" times";[/indent] - $downloadNow="Download";//this can also point to an <img src=\'assets/images/download_button.gif\'alt=\'download\' />
2007/10/28
1.2 Added text counter file write function to reduce the code.
Added capability to set the download directory from the snippet call.
Improved Error reporting.
1.3 Added file size in human readable format
Click here to download this file
Edited by Cris D., 01 November 2007 - 10:11 AM.











