Save As button

Discussion in 'PHP' started by newlearn, Aug 27, 2007.

  1. #1
    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.
     
    newlearn, Aug 27, 2007 IP
  2. ssanders82

    ssanders82 Peon

    Messages:
    77
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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?
     
    ssanders82, Aug 27, 2007 IP
  3. newlearn

    newlearn Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well yes.
    I wanted to have a "Save" button instead of telling vistors to right click on image and save it.

    Any ideas.
     
    newlearn, Aug 27, 2007 IP
  4. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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.
     
    sea otter, Aug 27, 2007 IP
  5. ssanders82

    ssanders82 Peon

    Messages:
    77
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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.
     
    ssanders82, Aug 27, 2007 IP
  6. ssanders82

    ssanders82 Peon

    Messages:
    77
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    damn you sea otter, you beat me by 1 minute ;)
     
    ssanders82, Aug 27, 2007 IP
  7. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #7
    We were typing at the same time. But you at least posted some code. I got lazy :p
     
    sea otter, Aug 27, 2007 IP