Page 1 of 1

Uses of fpassthru()

Posted: Thu May 23, 2002 11:15 pm
by Benjamin
I am interested in hearing about the different ways which fpassthru() can be used, and some sample code bits from any of you who have used it in the past.

One question that I have is...

If I have a html page which has an image source tag in it set to be <? getimage.php?show=dog ?>

and then getimage.php had code in similar to this...

<?
if (show == $dog)
{
$dog = "./images/dog.jpg";
fopen $dog;
fpassthru($dog);
fclose $dog;
}

would that work?

Re: Uses of fpassthru()

Posted: Fri May 24, 2002 3:03 am
by duke9
agtlewis wrote:

Code: Select all

$dog = ".images/dog.jpg";
fopen $dog;
fpassthru($dog);
fclose $dog;
You need to send the correct MIME type before the file contents, like this

Code: Select all

header("Content-Type: image/jpg");
This forces the browser to interpret the following data as an image

Posted: Fri May 24, 2002 3:07 am
by Benjamin
So it would look like this?

Code: Select all

<? 
if (show == $dog) 
&#123;
header("Content-Type: image/jpg");
$dog = "./images/dog.jpg"; 
fopen $dog; 
fpassthru($dog); 
fclose $dog; 
&#125;
I didn't know you had to send a Content-Type header but it makes sense.

Posted: Fri May 24, 2002 4:43 am
by Benjamin
I have another question about this...

On a site that has a lot of hits, would this use up a considerable amount of system resources?