how to save picture not displayed ?

T

Tuckbros

Hi everybody,
I am doing a small site with picture to save. My problem is to offer
pictures to download, not to display. Can someone tell me how can I make
the "save as" dialog to open, without using the right clic and "save
target as".
Thanks in advance
 
F

Fat Sam

Tuckbros said:
Hi everybody,
I am doing a small site with picture to save. My problem is to offer
pictures to download, not to display. Can someone tell me how can I
make the "save as" dialog to open, without using the right clic and
"save target as".
Thanks in advance

Wrap up the images in a zip file?
 
S

Steve Pugh

I am doing a small site with picture to save. My problem is to offer
pictures to download, not to display. Can someone tell me how can I make
the "save as" dialog to open, without using the right clic and "save
target as".

You could lie about the mime type.

You could put the image in a zip file.

You could offer the image in a format that browsers don't usually
display (TIFF for example).

You could do nothing and let users see the image before deciding
whether they want to save it or not.

Steve
 
T

Tuckbros

Tuckbros said:
Hi everybody,
I am doing a small site with picture to save. My problem is to offer
pictures to download, not to display. Can someone tell me how can I make
the "save as" dialog to open, without using the right clic and "save
target as".
Thanks in advance

The images I plan to save are generated with a php script. An image with
poor quality but light is sent to the brother while a better is
generated as a jpg file and stored on the server. I made a link from the
light picture to the heavier, but it displays the image. And I would
like to save it instead of displaying.
I looked if I can compress it in a file but it will load the server for
quite nothing.
 
F

Fat Sam

Tuckbros said:
The images I plan to save are generated with a php script. An image
with poor quality but light is sent to the brother while a better is
generated as a jpg file and stored on the server. I made a link from
the light picture to the heavier, but it displays the image. And I
would like to save it instead of displaying.
I looked if I can compress it in a file but it will load the server
for quite nothing.

Can you post a link please?
 
F

Fat Sam

Tuckbros said:
a link to what ?

A link to the pages you have in place at the moment.....I'm not entirely
clear what you mean by "poor quality but light" and also when you talk about
sending an image to your brother......I thought if I could see the page it
would make it easier to understand, and therefore find a solution......
 
K

Karl Core

Tuckbros said:
The images I plan to save are generated with a php script. An image with
poor quality but light is sent to the brother while a better is generated
as a jpg file and stored on the server. I made a link from the light
picture to the heavier, but it displays the image. And I would like to
save it instead of displaying.
I looked if I can compress it in a file but it will load the server for
quite nothing.

Create a new PHP file and call it something like "downloadimage.php"

Access it like so:
http://www.example.com/downloadimage.php?img=foo.jpg

Where 'foo.jpg' is the name of the image you want them to download

<?php

/* image name */
$image_name=$_REQUEST['img'];

/* content type here. you could do some sexy stuff to detect it, or you
could hard-code it if you know that all of them are the same */
header("Content-Type: image/jpeg");

/* attachment disposition causes it to be treated like a download */
header("Content-Disposition: attachment; filename=$image_name");
readfile("../images/$image_name");
?>
 
T

Tuckbros

Dear Karl Core,
you are a master, thanks a lot.

instead of linking to the picture I linked to the php file containing
the following code :

$image_name = "../../sessions/" . session_id() . "/Avatar.jpg" ;
$save_name = "Avatar.jpg";
/* attachment disposition causes it to be treated like a download */
header("Content-Disposition: attachment; filename=$save_name");
readfile("$image_name");

where $save_name is the default name og the downloaded file and
$image_name is the name of the image to saved.

Karl said:
The images I plan to save are generated with a php script. An image with
poor quality but light is sent to the brother while a better is generated
as a jpg file and stored on the server. I made a link from the light
picture to the heavier, but it displays the image. And I would like to
save it instead of displaying.
I looked if I can compress it in a file but it will load the server for
quite nothing.


Create a new PHP file and call it something like "downloadimage.php"

Access it like so:
http://www.example.com/downloadimage.php?img=foo.jpg

Where 'foo.jpg' is the name of the image you want them to download

<?php

/* image name */
$image_name=$_REQUEST['img'];

/* content type here. you could do some sexy stuff to detect it, or you
could hard-code it if you know that all of them are the same */
header("Content-Type: image/jpeg");

/* attachment disposition causes it to be treated like a download */
header("Content-Disposition: attachment; filename=$image_name");
readfile("../images/$image_name");
?>
 
S

Steve Pugh

But he wants to do it without right clicking any thing.
I don't think it's possible.

3 of the 4 options I gave would lead to that result. So yes it is
possible, but there would be downsides that IMO outwiegh the
perceieved benefit.

Steve
 
J

Jukka K. Korpela

Richard said:
But he wants to do it without right clicking any thing.
I don't think it's possible.

Oh, then you need to learn how to use your browser better.
Or switch to an advanced browser like Lynx, which is excellent for
downloading images (on well-designed sites).
 
T

Travis Newbury

Oh, then you need to learn how to use your browser better.
Or switch to an advanced browser like Lynx, which is excellent for
downloading images (on well-designed sites).

So what you are really saying is that is sucks for downloading images on
most of the web. (And before everyone jumps on me for trashing lynx, I
am trashing most of the web, not lynx.)
 
J

Jukka K. Korpela

Travis Newbury said:
So what you are really saying is that is sucks for downloading
images on most of the web.

No, that's your idea and your words (and pseudo-sentence).
 
G

Guest

Tuckbros said:
instead of linking to the picture I linked to the php file containing
the following code :

$image_name = "../../sessions/" . session_id() . "/Avatar.jpg" ;
$save_name = "Avatar.jpg";
/* attachment disposition causes it to be treated like a download */
header("Content-Disposition: attachment; filename=$save_name");
readfile("$image_name");

where $save_name is the default name og the downloaded file and
$image_name is the name of the image to saved.

One thing I'm sure someone will mention (if they haven't already - I'm offline)

Be very sure that you're getting your filename from a trusted source, Ie:

$img = $_GET['IMG'];
readfile("/dir/" . $img); /* This is not safe */

Because some clown could come along and enter: IMG=../etc/passwd

Looks like your base is covered pretty well, unless Mr. clown comes along
and issues a bogus PHPSESSID. (or whatever your session variable is
configured as) even then, it'd be hard to get around the Avatar.jpg portion,
and I imagine their ability is limited by session variables which would likely
disappear if they tampered with it.

Using a regular expression or something to strip special characters or testing
from a list to ensure IMG is actually what you'd intended are some common
techniques.

I just wanted to mention it in this thread in case someone is googling
for the same problem. Looks like you took care of it, someone reading along
might not be aware of it. (it is an easy thing to miss)

Jamie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top