1

I am creating an app that involves letting the user import and export photos. I believe I have importing worked out fine using

<input type="file" />

but I cannot find a way to create an export button that functions in a similar way. As in, it brings up the directory listing as lets the user choose where to save the picture that is currently being displayed.

4
  • 1
    an export would be a link or call to the server to serve up your file. Commented Jun 6, 2013 at 18:27
  • 3
    <a href="downloadImage.php?img=pathtoimage">download image</a> and have downloadImage.php return the image with the attachment header forcing a download. Commented Jun 6, 2013 at 18:28
  • 2
    You want a button that replicates the user "right-clicking" on the image and choosing "Save Image As"? Commented Jun 6, 2013 at 18:28
  • 3
    serve the file you want with mimetype application/octet-stream and then browser will be force to download. Commented Jun 6, 2013 at 18:29

1 Answer 1

2

You can't directly trigger a "Save as" dialog from a web application, but you can serve the image in a way that will make the browser do it.

You need to send the Content-Type (mime type) to something like image/jpeg and Content-Disposition to something like attachment; filename="fname.ext"

As Kevin B suggested, you can accomplish this using PHP. I don't think there's a way to do it with only JavaScript.

Sign up to request clarification or add additional context in comments.

1 Comment

Alright its got to be done server-side, thanks to everyone that responded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.