PDA

View Full Version : Is this possible?



Wojtek
December 21st, 2003, 01:44
Instead of having someone right-click on an image and save as,
the person clicks on the image as if it were a link and the save as dialog appears

Loon
December 21st, 2003, 08:36
I can't think of any possibile way you could do that, short of writing some sort of dll that the user would need installed.

Decker
December 21st, 2003, 09:57
You could try hyperlinking it to a duplicate file with the extension changed (to .zip or smething else that automatically downloads).

Either that or it's coding time :-)

Loon
December 21st, 2003, 13:38
hmm, actually, come to think of it, you could force the file to download using .htaccess


<FilesMatch "\.(gif)$" >
ForceType application/octet-stream
</FilesMatch>

Try this, as an example for any .gif images, then just link to the image like any other file domain.com/image/pic.gif

Was half asleep earlier, not thinking straight :cry2:

* edit, make sure the .htaccess file is in the same directory as the images you want to force to download. If you want to use multiple file types, seperate them like gif|jpg|png

Wojtek
December 21st, 2003, 18:10
Hello,

I've tried that and it still dosnt work,
it just displays the image in the upper left corner of the browser, dosnt pop save as dialog :(

Any help?

GibboNet
December 21st, 2003, 23:58
Normally you'd try to prevent people from downloading their images. :confused5

I can't think of a way that it could be done, and I sure haven't ever seen a site that does it.

What do you need to do this for ? Maybe there's another way....

Loon
December 22nd, 2003, 08:48
ok, are you on a cPanel server? if so you should have access to add/edit mime types, you could try the following.

There will already be an entry for application/octet-stream with extensions like .exe .class etc you could add image extensions, .gif .jpg .png etc, that would work but it would mean all images you link to would download.

Other than that, i'm sure you could do this with headers instead of .htaccess lemmie go try :-)

Loon
December 22nd, 2003, 10:33
ok, here you go:

save the following as anything you like, in the same directory as the images, e.g download.php



<?

$file = $_GET['file'];

$ext = explode('.', $file);
$file_ext = strtolower(".". $ext[1]);

if ($file_ext == ".gif" || $file_ext == ".jpg")
{
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=".$file);
@readfile('./'.$file);
}
else {
exit;
}

?>

Then to link to an image you want to download just use http://yoursite.com/path/download.php?file=pic.gif and it'll popup the download box (in IE at least, should be ok in netscape too)

Tested and working, it's setup just for .gif and .jpg files at the moment, i'm sure you can see how to add to that or just ask.

DO NOT edit the script and just use the header and readfile parts, i added the rest so that people can't just download any file they want via the script, including config files with passwords in etc

Hope it does what you need. :-)

Wojtek
December 22nd, 2003, 11:56
Exactly what I needed.

Thanks ALOT Loon :biggrin2: