Jump to content

Force download of an image


tinfanide

Recommended Posts

How could I force the browser to download an image on an anchor link instead of displaying the image itself?Is it a HTML thing or a PHP's one?I looked for it online and there're different opinions:HTML:

Content-disposition: attachment; filename=fname.ext

They said needed to change the header meta tag???PHP:

header('Content-Disposition: attachment; filename="love.gif"');

Somebody said it was a server-side thing, not client-side...JS:

<html> <body> <script>  function downloadme(x){ 	myTempWindow = window.open(x,’’,’left=10000,screenX=10000’); 	myTempWindow.document.execCommand(’SaveAs’,’null’,x); 	myTempWindow.close(); } </script>  <a href=java script:downloadme("/test.pdf");>Download this pdf</a> </body> </html>

But the JS seems broken...

Link to comment
Share on other sites

PHP:

header('Content-Type: application/force-download');header('Content-Disposition: attachment; filename="love.gif"');

i don't think you need the execCommand('SaveAs') call as the force download header should open that.also the close() call might close the window before the file is downloaded.the url to window.open() should point to a .php file to make use of the header() calls.

Link to comment
Share on other sites

PHP:
header('Content-Type: application/force-download');header('Content-Disposition: attachment; filename="love.gif"');

i don't think you need the execCommand('SaveAs') call as the force download header should open that.also the close() call might close the window before the file is downloaded.the url to window.open() should point to a .php file to make use of the header() calls.

I see.I'll try it later as I'm just learning the very simple bit of PHP at present.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...