Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
How to download images with proper file names rather than numbers?
I am running into a problem where people are downloading site imagery and then becoming confused by the filename being a number (e.g. ‘302.jpg’) rather than a description (‘2013_Toyota_Coupe.jpg’). These are people who are downloading many images and the content of the image isn’t always obvious by looking at it.
Is there a way to solve this with creative Textpattern tags? I’d like to serve up the full filename + ext.
If not, is there a way to solve this with e.g. an external PHP script, passing some URL vars to it and letting it generate a properly-named file?
Just curious if others have tried and solved this problem. Thanks!
Last edited by maruchan (2012-09-27 21:15:36)
Offline
Re: How to download images with proper file names rather than numbers?
Anything in this post of any use?
Failing that, how about a trick? Whip up a plugin that hooks into the file_download
event such that if you detect site.com/file_download/image/<ID>
(or something), go and fetch the image file and serve it as a download. All you then have to do is make your thumbnails clickable (or add a ‘save to my computer’ link) to direct them to the ‘fake’ download link.
Won’t stop people right-clicking and downloading the thumbnails, but it should capture the full-size images.
Not sure if that’d work as I’ve not really thought it through, but it might be worth a shot if the htaccess approach doesn’t give you any joy.
Last edited by Bloke (2012-09-27 21:43:00)
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
Online
Re: How to download images with proper file names rather than numbers?
Thanks, Stef. Does the .htaccess trick actually provide the user with a file that is so named, or does it translate the filename and pass them through to 302.jpg in a sort of redirect-y way? If the former, that’s probably what I’d do. Not enough plugin-writing experience yet. :-) Also the file handler might not work since the image has to open as an image rather than a “save as” prompt. Just guessing.
Last edited by maruchan (2012-09-27 21:55:07)
Offline
Re: How to download images with proper file names rather than numbers?
maruchan wrote:
Does the .htaccess trick actually provide the user with a file that is so named
I’ve never tried it, but I assume it’s still got to serve the physical file, which is a numeric value.extension. That’s why I wondered if the file download version might work because you can use the attachment header and alter the name so the file takes on the name you specify when it hits the user’s computer.
It depends how you are showing the pics of course. Nothing to stop you showing the full size image on the screen, say, 302.jpg and then making it clickable so the href="/file_download/image/302.jpg"
. Then when someone wants to save the file they just (left) click / tap it, the plugin looks at the URL, which would ordinarily 404, fetches the actual /images/302.jpg
content, looks up the meta info in the database and serves the image as Spongebob-footmuff-ambulance.jpg
. I’d have to try it to see if it works.
But there’s probably an htaccess trick that’ll do it. Not my core competence though so you’d need to raise the bat signal to find a guru.
Last edited by Bloke (2012-09-27 22:09:10)
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
Online
Re: How to download images with proper file names rather than numbers?
maruchan wrote:
Thanks, Stef. Does the .htaccess trick actually provide the user with a file that is so named, or does it translate the filename and pass them through to 302.jpg in a sort of redirect-y way? If the former, that’s probably what I’d do.
Offline
Re: How to download images with proper file names rather than numbers?
That’s terrific news. :-) Thanks!
Offline