/    Sign up×
Community /Pin to ProfileBookmark

save images on click

Quick question. How do you allow the user to download a image, not link to it? (simlar to gmail)

to post a comment
HTML

10 Comments(s)

Copy linkTweet thisAlerts:
@jshalcottApr 17.2006 — Simply put it is a compressed folder (.zip), then put a link to the compressed folder. Like this [B]http://www.yoursite.com/images/[I]download.zip[/I][/B]
Copy linkTweet thisAlerts:
@glenvernApr 17.2006 — I assume the zipped file will automatically download itself

to the users computer once they click on the URL -

I ask this as I am looking for a similar downloading code but

I am trying to avoid the zipping bit and I dont want to use

the "Right Click Save as".. I prefer a "Download here" button.

(the file that will be downloaded is a .txt file)..

If zipping is the only way to go which is the best way to

zip a .txt or an HTML file (never done it before)
Copy linkTweet thisAlerts:
@felgallApr 17.2006 — The only other way to do it is to use a server side language to force the download.
Copy linkTweet thisAlerts:
@pcthugApr 17.2006 — Or pass image through FTP, though using server side Content Types you should also be able to promt a download
Copy linkTweet thisAlerts:
@blah1985authorApr 18.2006 — I know Gmail does it, anymore hints? Possibly if I explain more. I created a slideshow generator 100% js for code and would like to allow the user to dowload the image after clicking on it. Btw if you would like to see my its at http://armor4life.com/photos.php click on any "slide show" and hit start/stop slidshow
Copy linkTweet thisAlerts:
@blah1985authorApr 18.2006 — btw I can use PHP or other languages
Copy linkTweet thisAlerts:
@nitrexoxideApr 18.2006 — Not sure, tried google?
Copy linkTweet thisAlerts:
@pcthugApr 18.2006 — This PHP script will do the job. Save it as say [B]download.php[/B] and then put in the same directory as your images. To request an image use the following querystring:

[COLOR=Silver]http://w[i]w[/i]w.mydomain.com/path/to/[/COLOR][COLOR=Red]download.php[/COLOR][COLOR=Magenta]?image=[/COLOR][COLOR=DeepSkyBlue]myimage.gif[/COLOR]
[code=php]<?php
//get requested 'image' from query string
$image = $_GET['image'];

//cleanup and return
$image_extension = strtolower(substr(strrchr($image,"."),1));

//IE 'Content-disposition' hack
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');

//if no image specified, then
if( $image == "" ) {
echo "<h1>ERROR!</h1><br />n<p>No Image Specified</p>n";
exit;
}

//if requested image cannot be found, then
elseif ( ! file_exists( $image ) ) {
echo "<h1>ERROR!</h1><br />n<p><em>$image</em> not found.<p>n";
exit;
};

//force download of all image types (jpeg/jpg, gif, png)
switch( $image_extension ){
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
default: $ctype="application/force-download";
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: $ctype");
header("Content-Disposition: attachment;

filename="".basename($image)."";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($image));
readfile("$image");
exit();

?>[/code]
Copy linkTweet thisAlerts:
@jshalcottApr 21.2006 — i've been wondering how to do that, does this script also work with different kind of files, or do I need to edit it a bit or something.
Copy linkTweet thisAlerts:
@pcthugApr 21.2006 — This script only forces images (jpeg/jpg, gif, png) for download, however with a little editing you can make force virtually any file for download.
[code=php]
//example: this scrip would force download of all *.mp3
switch( $image_extension ){
case "mp3": $ctype="audio/mpeg"; break;
default: $ctype="application/force-download";
}[/code]
×

Success!

Help @blah1985 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...