I've had a requirement where I needed to create links to different size images (as generated by image cache), but when clicking on the image the image should download and not display in the browser.

I've added another menu option to 'path' => file_directory_path() .'/imagecachedl'. If this is the url for the image, the image will be bring up a download window in the browser.

Comments

diricia’s picture

Status: Active » Needs review
StatusFileSize
new1.49 KB
drewish’s picture

I'd suggest that the best way to achieve this is with an an apache header:

<FilesMatch "\.(jpg|jpeg|png|gif)$">
	Header set Content-Disposition "attachment"
</FilesMatch>
dopry’s picture

Status: Needs review » Closed (won't fix)

I won't be committing this, but it is a good pointer... Maybe a good candidate for a small helper module since it has wider application than just images.

mandclu’s picture

+1 for the original idea. Personally I like the idea of having this in imagecache, especially since it was accomplished with so little extra code and would allow you to selectively trigger downloads in certain instances and not others.

mandclu’s picture

Version: 5.x-1.5 » 6.x-2.0-beta4
StatusFileSize
new9.02 KB

FWIW, here's a D6 version that also allows for the same functionality. Slightly different structure required.

Also, I should mention the use case for this: I want to make wallpapers available in various sizes. With this small modification, I can now allow a contributor to upload a single file, and users will see an automatically generated thumbnail, plus get a convenient fool-proof download link.

mandclu’s picture

Version: 6.x-2.0-beta4 » 6.x-2.0-beta5
Status: Closed (won't fix) » Needs review
StatusFileSize
new2.38 KB

I re-wrote this as a helper module, but if you look at the code you'll see that except for adding a single header, this module essentially duplicates several functions from the original module. To me, the original changes proposed for imagecache were a much more elegant solution. In any case, here's the download function as a separate module.

drewish’s picture

Status: Needs review » Closed (won't fix)

it's won't fixed for a reason. you can do it with a 3 lines of apache config. if you want to release and add on module feel free to do so. also don't post .zips for review post a patch file.

mandclu’s picture

AFAIK, the Apache header you've proposed would force all images to download, which would be a disaster.

We want to be able to upload an image once, then use it in some cases for display within a page, and in other cases have it resized and forced to download. If all that can really be accomplished with three lines of code, I can't see how the three lines above will accomplish it.

Having this as part of imagecache, or even as a helper, could eventually allow even more extended functionality, such as a view display style that could display a thumbnail automatically linked to a download.

As for the .zip, guilty as charged. I can roll a patch if anyone shows any interest in this.

pol’s picture

I'm really interested in this... and changing apache config is a nonsense...

pol’s picture

khalemi’s picture

i'd like to see this patch as a helper module for imagecache, especially for the 5.x 2.4. currently we are building a stock photo site (fotografi.my), we still have no solution but to call javascript to open up a window and display a message for the user to download the image via "Save As"

marcoka’s picture

how did you manage to create different image sizes from one uploaded image. i try to upload one image and display different sizes for download at the bottom of the image.

mandclu’s picture

Pol's second link in #10 is an issue in the File Force issue queue, and I have to confess that File Force is probably the best way to address this, although installing a whole module for the sake of something that could be accomplished in this module with so little extra code does seem a tad excessive.

I think the only thing that would still be a big win would be providing a formatter that would make a nice GUI way to set up these downloads (think: "thumbnail linked to original (download)"). I'll open up an issue at File Force.

mandclu’s picture

@e-anima - set up imagecache profiles for the different sizes you want available for download, then use one of the methods in this thread (at this point I'd suggest File Force) to handle the imagecache path with the extra "download" token. You may need to do some extra theming to get the links structured properly, but hopefully a field formatter can be created to address that.

pol’s picture

Hi,

That's an old topic ! :)

My patch for D6 has never been accepted... and I still use it for my project without any problem.

marcoka’s picture

#6 not working here, tested it. any ideas?

why should this work -> $items[file_directory_path() .'/imagecachedl'] = array( ...

this path is never accessed, only if you manually relink the files. is that the intention?
at the moment im searching why modules like force_file and x-sendfile only work with the generic output formatter and not with links to /imagecache/preset...

thanks

shaundychko’s picture

Status: Closed (won't fix) » Fixed

Here's my solution:

1) put all uploaded images in the same folder, such as /sites/default/files/originals
2) put a .htaccess file in /sites/default/files/originals with the following lines:
<FilesMatch "\.(?i:jpg|jpeg|png|gif)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>

The "ForceType" is needed for Internet Explorer. The Regex is case insensitive and requires the match to occur at the end of the filename.

Be sure that the apache headers module is enabled (it isn't by default in Ubuntu 8.04 LTS). In Ubuntu, run
$ sudo a2enmod headers

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

AdrianB’s picture

it's won't fixed for a reason. you can do it with a 3 lines of apache config.

As pointed out in #8 the Apache header would force all images to download. But besides that most of us using shared hosting does not have access to the Apache config. #17 could work, but I'm not sure it works on all shared hosting. The original suggested solution was a more flexible way.

Edit: Tried File Force, didn't work. Tried this .htaccess solution (which is similary to those suggested here) and that worked.