I have a gallery page that lists medium and high resolution images of plants that users can download. However, the default behavior of a jpeg image inside an href is to open in the browser window. For these specific links I would like users to be able to download the image when clicking on the link instead of having to open the image in the browser and then save it.

Here is the code I have:

<div class="topic-links">
 <div class="topic col-sm-4 col-md-4">
  <img src="{gallery_thumb}" alt="temp_square-tn" width="220" height="200">
  <h6>{exp:char_limit total="30" exact="no"}{title}{/exp:char_limit}</h6>
    {if medium_res != ""}<a href="{medium_res}">Medium</a><br />{/if}
    {if high_res != ""}<a href="{high_res}">Large</a>{/if}
 </div><!-- /.topic -->
</div><!-- /.topic-links -->

What is the best way to force a download?

  • Think I needed to use a htaccess file to do this on a vcard previously. Server will need mod_headers installed for this to work. stackoverflow.com/questions/4218466/… – MBM Aug 21 '15 at 22:38
  • I confirmed that mod_headers is active on the server and added the code to an .htaccess file in that directory, but it is not working as desired. The image still opens in a browser window. – forrest Aug 21 '15 at 23:00

If using HTML5, you just need to add the download attribute

| improve this answer | |
  • Holy crap, up-vote for you. How did I miss that??? Thanks for answering! – jrothafer Sep 18 '15 at 6:06
  • I tried this but it does not work in all situations, even with modern browsers. – forrest Sep 22 '15 at 22:32
  • chances are you missed something, caniuse is one ressource to be trusted – laurent Sep 23 '15 at 8:59

This is not possible. The browser chooses how to handle these files, and that is client side. That's why

Right click to download

Is a thing. A user would have to configure their browser or use a third party browser addon to do this. Sorry, chief.


If you force the mime type, it's possible. But to do it selectively will require (if possible) some serious hacks, I'm betting.


Edit on my way to a party on a train, so I'm bored, lol.

You could make a custom module that you link to, like this:

Link to address: domain.com/?ACT=123&imagepath=images/myimage.jpg

And in your module, use this answer:


And throw an exit() after. I don't know, killing time on the train! Hopefully leads you in a successful direction.

Last Edit


Set your header for the octet/stream header, then try that function! I don't get paid enough :p

| improve this answer | |

This is possible and the solution is quite simple:

  1. add the reference to the image in an anchor tag: Medium
  2. Add the following code to the .htaccess file:

Header set Content-Disposition attachment

Example: http://southernlivingplants.com/resources/image-gallery

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.