Hi I have a coupon image on a webpage and I need to have a download button on that webpage. Clicking on download button will save the image in the local directory. I tried searching online for PHP code. I did not find anything. Can asomebody help me please.
Well, the easiest way would be to say "right-click on this image and choose Save As". The browser has a built-in save-as function, do you really need to replicate it?
Well yes. I wanted to have a "Save" button instead of telling vistors to right click on image and save it. Any ideas.
This page for the header() function in the PHP documentation explains how to send headers to the browser to force a download (which in turn opens your browser's "save as..." dialog box): http://us3.php.net/manual/en/function.header.php You can then wire that up to a "Save" button in a form. Don't forget to read the user comments on that page as well.
Ok, hmm, take a look at making another page called serveImage.php with the code: header('Content-Disposition: attachment; filename="filename.jpeg"'); Code (markup): When they click "save as", try loading serveImage.php in a hidden frame using Javascript. I think this will prompt them to save the image; you may have to play around with the php header settings. I'd try it myself but I've gotta run now, let me know if it works.