I need to provide a button on a webpage that can optionally cause an image file to be downloaded and stored in the client's filesystem. I thought to use the approach from Force a file or image to download using .htaccess and wrote in my .htaccess, following the style of the Apache documentation,
<If "%{QUERY_STRING} =~ /download/">
Header set Content-Disposition attachment
</If>
I then provide a link like http://www.example.com/images/image123.jpeg?download=true, and that works fine with my production server. But it gives me an error 500
on the Mac development system on my desk, using either OS/X's apache or MAMP. Apache complains it does not understand the <If>
statement, and serverFault tells me that is not understood by Apache 2.2. Both OS/X and MAMP provide Apache 2.2.
Is there a way I can rewrite the <if>
statement to produce the same effect in Apache 2.2, please?
I can't just use
<a download="clientFileName.jpg" href="/images/image123.jpeg">Download</a>
because it doesn't work in either IE11 or Safari.