I am looking for a way to force the browser to download an image instead of just display it.
I already looked a lot (and deeply) and there seems to be no standard way to do it properly.
The way Facebook do it, it’s with some PHP I guess they put a parameter at the end :
?dl=1
So it’s certainly a PHP page behind with an url rewritting i guess
<a class="itemAnchor" role="menuitem" tabindex="-1" href="http://a5.sphotos.ak.fbcdn.net/hphotos-ak-ash4/327910_2733459209258_1040639162_2895571_6924037615_o.jpg?dl=1" rel="ignore"><span class="itemLabel fsm">Download</span></a>
So if you have any clue how they do it… My clue is that they probably do something in the headers of the PHP page
They simply force downloading using HTTP headers just like you do with any other file:
X-SendFile
For larger files or busy webservers, I would suggest the use of X-SendFile header instead of using
readfile()function (note that you needmod_xsendfileinstalled in Apache)..htccess
As you noticed, the Facebook URL points at a jpg file, rather than a PHP one.
You will need to have URL rewriting in a
.htaccessfile to do this trick.Something like the following should work (note you will need to use the real URL, checking the contents of
$_SERVERto do so).