So- I’m finally putting up an EE website and as I was screwing with the CSS for the billionth time and concluding the site really was that butt ugly I decided it would be much more fun to write a module to handle my downloads. Basically I wanted something simple- require membership (or specified group) to download, hide the actual folder holding the downloads and maybe keep some basic stats. NOTE- right now, it’s only designed to handle zip files- if somebody ends up wanting it to force media downloads, I’d have to dink with it. But honestly- I figure it will mostly used by folks like me who want to keep track of scripts being downloaded.
Anyway, only took 2 days to write it and another 2 for the stupid documentation. Still beat screwing with css for another minute. You’ll find the download here- er, but you’ll have to be logged in to see the link (course, I did that bit with pure EE conditionals). And don’t worry- I made membership with no confirmation, so if you want the module you won’t have to jump through hoops for it.
If you WERE logged in, you’d see a link with this url: http://media-cow.com/?ACT=27&ID=2 - basically, it’s passing the entry_id, then using that to grab the filename from a custom field in the weblog entry, then serving up the file from its ‘secret location’. If you aren’t logged in or don’t meet the membership requirements, you get served with an error and a link to the main site.
And then I added a little htaccess file to the download folder- which if it works on your server means that even if they know the ‘secret folder’ and/or true url- which in this case would be http://media-cow.com/d-stuff/mod.download_lock.zip, it can’t be accessed via http anyway. So- should be pretty secure. Especially if you don’t go around posting the url of your secret folder.
Which is all rather moot as any software worth stealing can be easily had anyway. But hey- it’s still cool. I would kind of like to at least halfway keep track of who is downloading what.
Anyway- it’s in beta. The first step of which is seeing if the download works for you- but only when it should.
Also- have you noticed nobody sees stuff posted below the fold? Including me. That sucks. Somebody go try it out. Should be maintained as I’m actively using it. Not really planning to add much to it as it does what I need- but if folks need stuff, can’t hurt to ask. A license ‘confirm’ form wouldn’t be a bad idea. But then I’d have to write a license. Er- a different license. Anyway- put it to the test, let me know where it breaks.
rob,
thank you for your hard work. i think this is a great addition to EE.
i will like to make a request. i like to add other file types (with a user’s choice, if possible), including .jpg, .gif, .bmp, .png, .rar, .txt, .mp3. i will also like to have this feature cover user-selected directories (as these files can be stored across multiple directories and subdirectories).
are these possible?
Thanks for this Rob it looks like it’ll do just what I want it to but can I make a request for pdf support? I want to protect and log document downloads. Also, does the logging functionality store references to the individual members that downloaded a file with relevant time and date information? Sorry if this is obvious from reading the php source… I’m just learning php… slowly! Thanks again for this module, Rob
Man- I really don’t look below the fold much. I’ll see what I can do about adding the other file types. On the one hand, it’s easy to do. On the other hand, it’s one of those things where you run into browser specific differences, which can make it a pain to test and get working correctly on EVERYTHING.
As to user-selected directories, that will take more thought. I had considered allowing different directories with different config options (x group can download from this directory, y group can download from another)- but it adds an extra layer and more overhead, which I didn’t need, so I avoided. Anyway- that bit will take more time as if I do it, I want to be sure there’s a simple mode that avoids the extra overhead.
As to stats- it does record the date of the last download a person made and how many times they’ve downloaded (though an interrupted download will get counted twice). Would be pretty easy to add an extra column and keep both the date of the first and last download. And I don’t think the stats tag actually shows the individual level data, but it would be easy enough to add it in- probably via another tag.
Anyway- will dink with adding the other file types today.
Hee- it’s a really simple mod- most of the tricky bit is straight from:
// Header bit is taken pretty much verbatim from PHP manual discussion on readfile() http://us3.php.net/readfile
As per my extremely messy commenting in mod.download_lock.php. But putting it into a mod beat mucking about with css any day!
OK- got a v2 up for testing- and I’d advise testing before downloading. New script same place as the old- download and instructions here (no alterations to the db, so if you’ve already installed it, all you really need to do is replace mod.download_lock.php with the new file.
Also- before doing so, I’d suggest/request you burn some of my bandwidth on this page- I’ve got txt, pdf, jpg, gif, wmv, mp3 and bmp files up. They all download fine for me, but this is definitely one of those things where browser issues can crop up. So- I’ll say downloads look good in IE on pc. If you run into a problem with any, let me know here. If you download them all/whatever you want and are using a different browser, chime in and let folks know it’s all good.
File types that SHOULD work (but haven’t all been tested): txt, pdf, gif, png, bmp, jpg, mp3, wmv, zip, exe, qt/mov, doc, xls, ppt, avi.
I’m still doing this using readfile()- and I really didn’t think the 40mb file would work (er- it’s Hellsing- don’t download it if you aren’t into anime and vampires and on bb- I needed something big but not too big a pain to upload- you guys missed out on the Blake’s 7 option!). But it did, so I didn’t go with my other option. However- if you’re using this for a lot of REALLY large files, it’s possible you’ll run into memory problems. If so, let me know. I’ve got a different approach I could try.
Next version I’d like to add in an option for a TOS confirmation and tweak the stats a bit. I may dink with multiple folder options, but that’s expanding the script beyond what it was really intended to do.
Hi Rob,
First of all a massive thank you for all the hard work that you must have put in to get this module working. Thanks for that. I am just about to install the module now and test it out but what I would really love to have is a download module that can achieve the following :
1 - Offer users downloads based upon the group(s) they are allowed access to.
For example if you have say three groups in EE called :
Group 1 - PDF Downloads Group 2 - Audio Downloads Group 3 - Text Downloads
Of course they do not have to be named like this, just an example. If then a user belonged to ‘Group 1’ they could then see a list of files that they could download.
I don’t know if this is possible at all but would make the start of great workings for a kind of e-commerce come downloads module.
Thanks again for all your fantastic work.
Regards,
Mark Bowen
OK- I was using this on a client site, which inspired some tweaking. So- new version is up.
The big improvements- * It will automatically figure out the path based on standard EE inserted {file_x} file browser specification- meaning as long as you are using the EE syntax, you can use mulitple folders and it will pick them up automatically.
I also added the ability to pass the custom field id in the link- that means you can ‘protect’ a link in any field, not just one specified field.
Also added 2 hooks- one takes over statistics functions- so you could write an extension to insert counts in a weblog custom field, making it easy to show the number of downloads on a multi-entry page. You could do this before by tweaking the code, but now it’s simple to do, no tweaking involved. If there’s an extension to take advantage of it. I wrote just such an extension.
The other hook takes over permissions- I added it so I could integrate the module with the simple commerce module. I’ve also written a the extension to take advantage of that hook. I think that extension will probably be a pro one- and I’ll be asking for beta testers in another thread.
Added the ability to NOT require membership- so you can use it to simply force downloads and keep track of the number of downloads.
In short- just made the whole thing more flexible. You can download the latest version here, just replace the existing files with the new ones. It’s currently powering downloads on that site, so shouldn’t be too buggy.
And EE Lover- no telling what was up with not counting you. I’m always dinking with stuff on that site- which means breaking it routinely.
Thanks a lot Robin for this module. 😊 I’ve used version 0.1 until now and it worked fine so far.
* It will automatically figure out the path based on standard EE inserted {file_x} file browser specification- meaning as long as you are using the EE syntax, you can use mulitple folders and it will pick them up automatically.
Wow! This is a great feature!
As I’m not an ee expert, I’m not sure how to set it up. Could you just give an example how to configure path file and write file name?
Lets say, I had two download folders as subfolders of a “top_download_folder” at the root and expression_engine installed in an extra folder (not directly at the root):
root/ - expression_engine_folder - top_download_folder – sub_download_folder1 – sub_download_folder2
How would configure than the pathfile in mod.download_lock.php and how would I have to enter the file name (with what kind of ee_code) in my created_file_download_custom_field?
If you have a file browser setup and you upload a file via the regular EE file upload, it’s going to automatically stick in a url that looks like:
<a href="https://ellislab.com/asset/images/ent-partner-logo/download_lock_1_0.zip">download_lock_1_0.zip</a>
So- that’s all you’d have in whatever custom field(s) hold your download. Say I put that in a custom field with a shortname of ‘download’. Then, in my template- if I want the module to automatically figure out the path, it will. (Be sure to use full paths in your file browser settings.)
So basically- that’s what the ‘download’ field holds if I look at it in the ‘edit’ page- and on the template, I just put:
<a href="http://{exp:download_lock:link">Download</a>
It will generate the proper ‘fake’ link- and what happens, when the link is clicked, the module pulls up the contents of the download field- figures out the file browser- does a query to see the path for that file browser- and uses that path to find the file and serve it up.
You don’t have to specify the field_name parameter- if it’s not there, it will use the default. But you can- which means you can put a downloadable file in any custom field. If it’s not specified, then EE uses the default. Same deal with the path to the image- if you don’t use the {filedir_x} tag in the custom field, EE will fall back on the one specified in the default.
Make sense?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.