Page 1 of 1
[solved] image() question (possibly more of a html question
Posted: Sat Sep 04, 2004 10:26 am
by Coco
im using image() on a site im building with a friend, using it to supply images from a secure folder to the browser henceforth making it impossible to remote link, and to only view images your permissions allow. (im doing this by the <img src=makeimage.php?id=xxx> method)
the problem is this... some of the images the user is supposed to be able to right-click and save-as, however, the resulting dialogue comes up with 'untitled' filename, and bmp as the only availiable file type, when the image itself is a gif or a jpeg. is there any way to get round this? i tried <object> instead but thatdoesnt seem to be compatible with retrieving images via script
any help gratefully recieved.. sorry if this should have gone in a different forum
this is my image display, used after getting details from the db
Code: Select all
<?php
if(stristr($dataa['thumbadd'], '.jpg')&&(strlen(stristr($dataa['thumbadd'], '.jpg'))==4))
{
$im = imagecreatefromjpeg ('./' . $dataa['thumbadd']);
}
elseif(stristr($dataa['thumbadd'], '.gif')&&(strlen(stristr($dataa['thumbadd'], '.gif'))==4))
{
$im = imagecreatefromgif ('./' . $dataa['thumbadd']);
}
imagejpeg($im,'',75);
imagedestroy ($im);
?>
Posted: Sat Sep 04, 2004 10:53 am
by feyd
are you outputting a content type header? there's no need to use the image functions, you can just [php_man]readfile[/php_man] the image needed, however, you do need to send the proper content-types..
Posted: Sat Sep 04, 2004 11:51 am
by Coco
im not sure how to do that?
since the script is being called by a different script, can i really output content type headers? bearing in mind that the script is run up to 30 odd times a page
the problem i had was that if i did it all in one script, i couldnt output anything BUT the image, unless i saved the image, which makes it pointless since im trying to prevent unauthorised access
ill have a look into readfile tho
Posted: Sat Sep 04, 2004 12:04 pm
by feyd
each image call should output a content-type header. It should also specify the content-length too.
read [php_man]header[/php_man] for more details on outputing headers..
Posted: Sun Sep 05, 2004 6:17 am
by Coco
ok readfile didnt help, but it seems to be more efficient so im gonna stay with that anyway.
i tried the headers, it made no difference. Still, when you right click save as, it comes up as an untitled bmp.
i even tried calling the image script on its own, to see if the headers make it work, but it doesnt (my main script passes calls to the image script via <img> html)
in short, it will not output an image and maintain the filename and type when right clicking. I do not want to give the users direct access to the files.
this is my new output script. i didnt include content length on the header, as the main concern is the file type:
call using <img src="makeimage.php?id=xxx">
Code: Select all
<?php
// fetch image details from db
if(stristr($dataa['thumbadd'], '.jpg')&&(strlen(stristr($dataa['thumbadd'], '.jpg'))==4))
{
header('Content-type: image/jpeg');
@readfile('./'.$dataa['thumbadd']);
}
elseif(stristr($dataa['thumbadd'], '.gif')&&(strlen(stristr($dataa['thumbadd'], '.gif'))==4))
{
header('Content-type: image/gif');
@readfile('./'.$dataa['thumbadd']);
}
?>
Posted: Sun Sep 05, 2004 10:33 am
by feyd
you may want to specify content-disposition.. (where you can tell the browser the filename)
can you post a link to this page, I can run a script that tells me all the headers and things they are sending...
Posted: Sun Sep 05, 2004 2:49 pm
by Coco
ok i tried adding a content disposition header, but it didnt work...
heres my current display script, called as before... any ideas?
Code: Select all
<?php
if(stristr($dataa['thumbadd'], '.jpg')&&(strlen(stristr($dataa['thumbadd'], '.jpg'))==4))
{
$filename = substr(strrchr($dataa['thumbadd'], "/"), 1);
header('Content-type: image/jpeg');
header('Content-Disposition: image; filename="' . $filename . '"');
@readfile('./'.$dataa['thumbadd']);
}
elseif(stristr($dataa['thumbadd'], '.gif')&&(strlen(stristr($dataa['thumbadd'], '.gif'))==4))
{
header('Content-type: image/gif');
$filename = substr(strrchr($dataa['thumbadd'], "/"), 1);
header('Content-Disposition: image; filename="' . $filename . '"');
@readfile('./'.$dataa['thumbadd']);
}
?>
Posted: Sun Sep 05, 2004 3:17 pm
by feyd
feyd via PM wrote:it appears that content-length is what IE needs.. Firefox gets it right.
Posted: Mon Sep 06, 2004 12:19 pm
by Coco
solved
content length seems to be what it needed