Download Lock 1.0
Example:
You’re seeing the download module in action right here. If you aren’t logged in, you’ll see a message instead of a download link. If you are logged in, you’ll see a link to http://media-cow.com/?ACT=42&ID=2. The url to the actual file is disguised and the ‘fake’ url will not serve up the file to anyone who isn’t logged in. Feel free to click it and give it a try.
Installation/set-up
Download the zip file (you’ll need to be logged in to do this
). For basic functionality you may need to set some configuration options in download_lock/mod.download_lock.php, so open up the file. You’ll see:
// $field_id - Optional- you may specify a default field as the field holding your file- you'll need this if you don't specify a field_name parameter.
var $field_id = '22';
// $download_path - Optional- should be full path with trailing slash to a default directory holding your downloads. This is needed if you are not using the standard EE file directory tag in your fields.
var $download_path = '/home/me/public_html/secret_files/';
As of v. 1.0, these are optional fields- $field_id should be the field id number for whatever custom field you are going to use to hold the file name of your download. The download path is- well, the download path. There are lots of tweaks you can make to this module- but the basic set-up is done. Now upload the lang.download_lock.php file to system/lang/english/ and the download_lock folder (containing two files) to your system/module/ folder. Go to ‘Modules’ and ‘enable’ the module and you’re good to go.
Tags and variables
There are two tags available for this module:
{exp:download_lock:link} - Creates the link to your hidden file.
{exp:download_lock:stats}{/exp:download_lock:stats} - A basic overview of your download stats.
{exp:download_lock:link}
This tag creates your links for you and should be used inside your weblog tag a la:
{exp:weblog:entries}
<h3>{title}</h3>
{if logged_in}<a href="{exp:download_lock:link entry_id="{entry_id}" field_name="my_file"}">Download</a>
{if:else}You must be logged in to download.{/if}
{/exp:weblog:entries}
Yes, I am cheating and using ExpressionEngine’s own conditionals to determine what the link shows.
Parameters and variables
There is one required parameter- you MUST include entry_id={entry_id} just like it’s shown above.
The field_name parameter is optional. If you do NOT specify the name of the field holding the file, the module will use the $field_id specified in the configuration option. However, this is more flexible and allows you to have multiple ‘locked’ files, each in its own custom field.
There are a couple of other parameters- mostly for debugging purposes:
- show_message="yes" - if a visitor should not have access to the download and you have this parameter set to ‘yes’, they’ll see an autogenerated message instead of the url. This is set to ‘no’ by default- because otherwise you can screw up your hyperlinks.
- link_url_only="no" - if you are using show_message="yes" then you probably need to add this parameter as well. It will show a complete hyperlink to the ‘fake’ file location instead of the default- which is simply the url.
It’s simpler and more flexible to just use EE’s standard conditionals- but if you’re wondering why the heck the url isn’t showing up, this will output an actual message telling you to login.
{exp:download_lock:stats}
If you’re keeping track of your download stats, you might actually want to SEE them- this tag handles that. Basic usage:
{exp:download_lock:stats}
{title} - Downloaded by: {unique_downloads} members<br>
{/exp:download_lock:stats}
Yep- that’s the code I’m using to generate the list of ‘Favorites’ over there in the top right corner.
Parameters and variables
You’ve got your basic parameters:
- limit="” - number of articles to show (no pagination as yet)
- orderby="” - takes values title, unique_downloads, total_downloads, total_m_downloads, and last_down
- sort="” asc or desc
Variables:
- {title} - the title of the entry the download is associated with
- {unique_downloads} - the number of members who have downloaded the file
- {total_downloads} - the number of times the file has been downloaded
- {total_m_downloads} - the number of times the file has been downloaded THIS month- requires EE Cron plugin be installed
- {last_down format=” %Y %m %d"} - this is a date variable- the date of the file was last downloaded
Tweaking things out
Note that this module was created to fill a very specific need- handling my file downloads. Version 1.0 saw considerable flexibility added, and tweaking is safer and easier than before. If you want more from the module, or perhaps less, I’ve stuck the ‘tweak’ instructions on their own page- here.
Simple tweaks include:
- Turn the stats off
- Restricting access to specific member groups or ANY visitor (logged in or not) - rather than all logged in members
- Adding ‘super security’ via .htaccess, so that the folder denies all http requests and serves the files only via script
- Adding a basic cron job via the EE cron plugin- so you can show the top downloads for the month/week/whatever
- Add your download stats to the exp_weblog_data table so that you can show the number of downloads etc., using a custom field in the weblog tag
And that is pretty much that.

Bug reports: