php image display

dejitaru

Banned
Sep 29, 2002
627
0
0
I need a php file to display an image when called:
<img src=blahblah.com/some.php>

I know that you have to open the file and echo "Content type:" and such, but don't know how to do that.

thanks for any help
 
 

kt

Diamond Member
Apr 1, 2000
6,032
1,348
136
Say you want to display a JPEG file.

<?php
Header ("Content-type: image/jpeg");
echo $data;
?>

Where $data contains the image data.
 

RSMemphis

Golden Member
Oct 6, 2001
1,521
0
0
$link=fopen("image filename","r");
$data = fread($link);
fclose($link);

I did not look the commands up, so there may be a syntax quirk here or there, but it should work roughly like that.

Also, you can generate images on the fly, but you need to recompile PHP for that.
 

kt

Diamond Member
Apr 1, 2000
6,032
1,348
136
Originally posted by: dejitaru
thank you

$link=fopen("image filename","r");
What is "r"?

"r" is the parameter telling the function fopen() to open the file up for read only.


$filename = "yourimage.jpg";
$fp = fopen($filename, "r");
$data = fread($fp, filesize($filename));
fclose($fp);