Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[request] force image download plugin?
Does a plugin already exist that force-downloads an image rather than opening it in the browser?
I’m looking to create a “download original image” link that starts a download from a press image area much in the way that Flickr has a “download the image at this size” link. I have other image links such as preview images on that page so I can’t use a general htaccess solution to force the headers.
There are various scripts out there but it seems that most represent a security risk when called via a visible url of the kind http://www.yoursite.com/force-download.php?file=filepath
.
I am thinking of something similar like <txp:xyz_image_download id="image-ID#" link="1" fileprefix="myprefix_" />download original</txp:xyz_image_download>
which would then grab the details for that image ID from the database and produce a link that will initiate a download of the image with its original file name plus an optional prefix, e.g. "myprefix_my_image.png"
rather than “4.jpg” as happens at present.
Does something of this kind already exist? If not, would anyone be willing to package one of the above scripts into a function?
TXP Builders – finely-crafted code, design and txp
Offline
Re: [request] force image download plugin?
jakob wrote:
Does a plugin already exist that force-downloads an image rather than opening it in the browser?
If it does I don’t know of one.
BTW, possibly related: I’m toying with the idea of extending smd_remote_file to be able to handle “local” files outside the document root (thus still “remote” as far as TXP is concerned… ummm, just!) and also to subdirs of the files
dir if you wish.
I’ve sketched out the plan and this would in theory offer the ability to upload files (not images per se, though an image could be stored as a file…) via the Files tab to what is deemed a “secure” location. Anyone invoking a site.com/file_download/<id-number> on such a ‘secure’ file is told (politely) to eat their own trousers.
Using <txp:smd_secure_file_download />
would however perform some rudimentary but difficult-to-reverse maths to present you with a link like file_download/a572348fb9acbdb9e8
.
When clicked that link resolves to the real file, checks the file is allowed to be downloaded (I’m building in file expiry and fixed-number-of-downloads-per-file limits) and if it is, serves the file with full content-disposition, thus will always (in theory) be downloaded rather than opened in the browser.
This also opens up the ability of putting the scrambled link in an e-mail for paying clients and when they click the unique (possibly time-limited) link they are sent the file. I’ve been talking with trenc and others about the possibility of integrating this kind of thing into yab_shop for paid-for downloads but that part’s only theory at the moment so don’t get too excited ;-)
If you can wait a bit for me to get my head round it, this plugin might help you out. If not, umm, dunno off the top of my head, sorry.
Last edited by Bloke (2009-01-02 22:32:39)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: [request] force image download plugin?
Bloke, Is there anything you can’t do?
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: [request] force image download plugin?
MattD wrote:
Bloke, Is there anything you can’t do?
Scuba dive and play the ukulele. Simultaneously :-P
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: [request] force image download plugin?
Stef, you are quick!!
Using <txp:smd_secure_file_download /> would however perform some rudimentary but difficult-to-reverse maths to present you with a link like file_download/a572348fb9acbdb9e8.
When clicked that link resolves to the real file, checks the file is allowed to be downloaded (I’m building in file expiry and fixed-number-of-downloads-per-file limits) and if it is, serves the file with full content-disposition, thus will always (in theory) be downloaded rather than opened in the browser.
That sounds like a good idea, even a little more than I was looking for. For the moment I just wanted to provide a comfortable download with original filename while avoiding the download.php file from being mis-used for things other than those intended. Hiding the original files was less important.
… If you can wait a bit for me to get my head round it, this plugin might help you out
Sure I can wait. For the moment, I’ve adapted one of the above scripts to accept only an image number and target file name as parameters and to then go get the file from the specific /images folder on that domain. Then I hid the whole behind an htaccess rewrite rule that rewrite a link in the form /image_download/123/myfile.jpg
into mydownloadscript.php?&image=123&name=prefix_myfile.jpg
. Seems to work after a little testing but not tested in all browsers yet.
Then, using your all-singing-all-dancing smd_gallery
script, I changed my download links in the form accordingly. BTW: for the previews I’m using christophe beyl’s brand-new slimbox2 script that’s now built on jquery.
Last edited by jakob (2009-01-02 23:17:25)
TXP Builders – finely-crafted code, design and txp
Offline
Re: [request] force image download plugin?
jakob wrote:
That sounds like a good idea, even a little more than I was looking for.
That’s my modus operandi. Pack in more than anyone needs in the hope someone needs it one day *sigh* :-)
For the moment, I’ve adapted one of the above scripts to accept only an image number and target file name as parameters
Sounds like a good compromise and should work well cross-browser. Be interested to hear how it performs. There’s certainly no need for my complicated — virtually vapourware — plugin really, I just mentioned it in case it offered something that might eventually help in the absence of any other nuggets of goodness from anywhere else.
Then, using your all-singing-all-dancing
smd_gallery
script, I changed my download links in the form accordingly.
Sweet!
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: [request] force image download plugin?
Hi Stef,
Wondering whether you ever got to create this <txp:smd_secure_file_download />
?
I have the same need as Jakob, forcing an image download, but I dont know the first thing about PHP and not sure how to implement his solution.
Cheers ~ j
Offline