I have a link to an image that when click I want the user to be presented with the usual “file save” dialog button - How do I do this easily and safely with HTML and/or PHP. There will be other images on the page which I want normal behavior for.
If all of the images you are linking to are jpgs, in the same folder and you are using Apache, you could put the following code in a .htaccess file in that images folder.
Thanks for commenting - I agree normally it would be very strange behavior, but in the webapp I’m developing (purergb.com), which is essentially an online photo editor, I have a save link/button where I want the current image to be downloaded. Slightly hard to explain, if you visit the site it’ll be easier to understand. The save button currently doesn’t do anything, and people keep asking why doesn’t it - i.e. they’re expecting a save dialog box I feel.
Since people do generally know how to copy images in their browsers today, I’d remove a save button then and instead some text saying (whatever most browsers do… right click and Save?).
Or the save button goes to the larger/better version of the image… when people offer screen wallpapers they do this: the link just goes to the large image. The user is expected to save the image however they normally save images in their browsers.
Unless there’s some other way people offer stuff like that?
@Stomme poes - I know I definitely could do that - but I’m concerned that it interrupts the flow of the webapp. Also I’m seriously considering operating on a reduced resolution of the image (for speed reasons) and only allowing the download of the full resolution at the “save stage”
Web “apps” will always be limited by the browsers who access the web.
I’d be curious to see if j3ph’s suggestion works, though, and how your users like it.
yes I agree j3ph method sounds interesting, it would necessitate me moving the file to a dedicate folder first on the fly and then completing the click (as I don’t want want the other images to be effected). SO I’m not entirely sure how it would work.
it would necessitate me moving the file to a dedicate folder first on the fly and then completing the click (as I don’t want want the other images to be effected). SO I’m not entirely sure how it would work.
Hm, don’t all these images have something unique about their names? If they all have some pattern of text in their names then you could likely use a regular expression to pick out the ones who get the special treatment.
I tend to use the script here: “http://www.zubrag.com/scripts/download.php” when I’m making a page with obvious download links like “Click here to download our patient applicant form.” The default version requires all of the files to be in the same folder and then a get variable to specify the file to be downloaded from the folder, but you can use additional get variables to modify the path to the download file and split it up into as many folders as you want to.
In some instances (like when it’s being used on faux page in WordPress), you need to set the folder path to start at the root folder of the domain to work.