Making a script produce an image output

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Stoneguard
Forum Contributor
Posts: 101
Joined: Wed Aug 13, 2003 9:02 pm
Location: USA

Making a script produce an image output

Post by Stoneguard »

Ok, I know I have seen this recently, adn cannot for the life of me find it. I have working script which basically returns an image as the result of the page request. The problem I am having is it is also opening a second browser window when as well as displaying the image properly in the first window.

Here is the code I have. What am I missing?

Test.php

Code: Select all

<?php
header("Content-type: image/jpeg");

$file = "C:\\...\\image.jpg";

readfile($file);
?>
Calling html

Code: Select all

&lt;img src="test.php"&gt;
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

I'd use...

Code: Select all

header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
header("Pragma: no-cache");
header("Content-Type: image/jpeg"); 
$file = "C:\\...\\image.jpg";
readfile($file);
Never had the issue with another browser window opening tho...
Stoneguard
Forum Contributor
Posts: 101
Joined: Wed Aug 13, 2003 9:02 pm
Location: USA

Post by Stoneguard »

For some reason, it still occurs, even when calling it from another server.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

I use a similar thing.... <img src="image.php?makethumb=image.jpg"> but haven't had any trouble with extra windows opening either.

Which browser are you using?
Stoneguard
Forum Contributor
Posts: 101
Joined: Wed Aug 13, 2003 9:02 pm
Location: USA

Post by Stoneguard »

I am doing my development for IE 5.5 or later because of my customer base. I actually use IE 6.0. It may be something simple with my test page, I will work more on it tomorrow.
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Go to my avatar:

http://www.chaosdreamers.com/external/s ... .php/1.jpg

Do you get a <img src="wateverimage.jpg" /> or an image in the browser window with a source that is not viewable?

Maybe that's a start, since something could be missing.

-Nay
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

umm... stonegaurd: pm me on this with an im service and name (eg: aim:stonegaurd ) if you're still having issues. i have something that works in 6.0 and does a bunch of stuff with images, i jsut wanna talk realtime and make sure that what i have is close enough to what your doing to be applicable. if so i'll give you the script and you can go from there to figure out what's going wrong
Stoneguard
Forum Contributor
Posts: 101
Joined: Wed Aug 13, 2003 9:02 pm
Location: USA

Post by Stoneguard »

Nay, what you gave me is strictly an image with no source. This gave me the idea to test my image and make sure the test file returns the same, and it does. there is no viewable source with the image being returned from test.php. Thanks for the idea though, was definitely worth a thought!

m3, I sent you a PM. I am in the Eastern US, so you will most likely catch me during the daylight / evening hours here. :).
Stoneguard
Forum Contributor
Posts: 101
Joined: Wed Aug 13, 2003 9:02 pm
Location: USA

Post by Stoneguard »

Heh, I finally figured out my problem. User error :oops: . The page I was testing it with had an explicit window.open() in javascript way down near the bottom. Thanks for all the help!
Post Reply