Q: How To Create A Link For "save Image As" To Download An Image

Discussion in 'HTML & Website Design' started by Mafishioso, Oct 4, 2007.

  1. #1
    hello everyone..

    Can anyone help me?...

    How can I make a link for users to DOWNLOAD an image (prompts SAVE AS dialog box) without using Right-click?...

    (Images are from photobucket.com)

    Any script? code? Pls help.

    Thanks a lot in advance..


    Gene
     
    Mafishioso, Oct 4, 2007 IP
  2. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You cant dictate if a file is downloaded or displayed as it is down to individuals settings/ preferences/ what they have installed.

    The easiest way to achieve what you want would be to have the link to a zip'ed version of the image as very few will have web browser pluggins that automatically open zip files rather than giving the dialog box
     
    AstarothSolutions, Oct 5, 2007 IP
  3. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Send headers indicating it is an attachment, namely "Content-Disposition: attachment; filename=image.gif"
     
    krt, Oct 5, 2007 IP
  4. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Not 100% reliable but a good suggestion - though you would have to link to a server side page rather than direct to the image as far as I can think you cannot add a header either to a link itself nor an image file directly
     
    AstarothSolutions, Oct 5, 2007 IP
  5. geertj

    geertj Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It can be done with javascript, but when opening the save-as dialogue the image also opens in a new browser window.
    The work-around avoiding a new browser window opening is as follows:

    The save-as script in the header:

    <script>
    function SaveFile(fname){
    img.document.execCommand('saveas', null ,fname)
    }
    </script>

    Now the trick is to have the image already opened as a new page.
    To achieve this we put it in an iframe with the image filename as SRC:

    <iframe id="img" src="myimage.jpg" width="(image width + 20)px" height="(image height + 25)px" scrolling="no" frameborder="0px"></iframe>

    On the original page we now call the save-as script:

    <button onclick="SaveFile('myimage.jpg');">save as</button>

    Does not work in FireFox though.....
     
    geertj, Feb 23, 2009 IP