Page 1 of 1

PHp file in IMG tag

Posted: Mon Sep 01, 2008 5:29 am
by sanju
Hi all,

Please look into my code TWo files..

1. <?php
include_once("../configure/config.php");
include_once("../lib_classes/class.DBaccess.php");
$me = new DBaccess();
$read_status = $me->readData("person", "person_id=".'21', "profile_photo, image_type");
if($read_status[0] == 1)
{
$image = $read_status[1][0]['profile_photo'];
$type = $read_status[1][0]['image_type'];
}
header("Content-type: ".$type);
echo $image;
?>

2. AND I am calling the file with an img tag..

<tr><td rowspan="7" align="left" valign="top"><img src= "show_profile_photo.php" width="114" height="104">

But here image is displaying after page is being refreshed. Not updating the image at first
time.

What I should I do to correct it..
Please help.

Regards

Re: PHp file in IMG tag

Posted: Mon Sep 01, 2008 5:33 am
by onion2k
You need to send a cache control header eg

Code: Select all

header("Cache-Control: no-cache");
Your script has another problem though.. if $read_status[0] is not 1 then you'll get a broken image.

Re: PHp file in IMG tag

Posted: Mon Sep 01, 2008 5:41 am
by sanju
Thank you for your help

I will correct it..

Re: PHp file in IMG tag

Posted: Mon Sep 01, 2008 6:04 am
by sanju
Hi

Still its not working.. :(

Re: PHp file in IMG tag

Posted: Mon Sep 01, 2008 6:52 am
by onion2k
sanju wrote:Hi

Still its not working.. :(
What headers have you added?

Re: PHp file in IMG tag

Posted: Mon Sep 01, 2008 6:59 am
by sanju
hi here is the file,..

session_start();
include_once("../configure/config.php");
include_once("../lib_classes/class.DBaccess.php");
$me = new DBaccess();
$read_status = $me->readData("person", "person_id=".$_SESSION['login_member_id'], "profile_photo, image_type");
if($read_status[0] == 1)
{
$image = $read_status[1][0]['profile_photo'];
$type = $read_status[1][0]['image_type'];
}
else
{
$image = file_get_contents($me->base_directory.'images/man.gif');
$type = 'image/gif';
}
header("Content-type: image/jpeg");
header("Cache-Control: no-cache");
imagejpeg($image);

REgards

Re: PHp file in IMG tag

Posted: Mon Sep 01, 2008 8:13 am
by onion2k
What other cache control headers have you tried? Or did you just try what I suggested without bothering to read up on what the header does, and now you're back on here expecting people on the internet to do your job for you because you're too lazy to do any research?