PHp file in IMG tag

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
User avatar
sanju
Forum Commoner
Posts: 65
Joined: Sat Jun 21, 2008 2:15 am
Location: Kochi, India

PHp file in IMG tag

Post 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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: PHp file in IMG tag

Post 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.
User avatar
sanju
Forum Commoner
Posts: 65
Joined: Sat Jun 21, 2008 2:15 am
Location: Kochi, India

Re: PHp file in IMG tag

Post by sanju »

Thank you for your help

I will correct it..
User avatar
sanju
Forum Commoner
Posts: 65
Joined: Sat Jun 21, 2008 2:15 am
Location: Kochi, India

Re: PHp file in IMG tag

Post by sanju »

Hi

Still its not working.. :(
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: PHp file in IMG tag

Post by onion2k »

sanju wrote:Hi

Still its not working.. :(
What headers have you added?
User avatar
sanju
Forum Commoner
Posts: 65
Joined: Sat Jun 21, 2008 2:15 am
Location: Kochi, India

Re: PHp file in IMG tag

Post 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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: PHp file in IMG tag

Post 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?
Post Reply