Page 2 of 2

Posted: Sat May 31, 2003 5:09 pm
by nickvh
stuart wrote:
Galt wrote:I dont believe that works, since you've already sent text before the header() method. Plus readfile() just dumps the actual file contents, so your code will look like (if the header() command is taken out):

... <td> #$U%I#%U#IO$%U@#%BINARY_FROM_JPEG_FILE@#$J%J@#% </td> ....

I'm gonna try the .htaccess code now ... hope that works.
You can call an image binary from anywhere in your script (even if headers have already been sent). You just do this:
getimage.php

Code: Select all

$file = $image."jpg";
header('content-type: image/jpeg'); 
echo readfile($file);
yourscript.php

Code: Select all

<html> 
<body> 
<table> <tr> 
<td> Some text </td> 
<td>

<img src="getimage.php?image=yourfile">

</td></tr></table> 
</html>
I use includes to get images from a database, so the above should work (I didn't test it though :) )
The above works, I like to use it for counter scripts when I have to pass on vavascript data(browser, screen size, etc.) to a php script. I make javascript make a <img src="track.php?browser=***&height=***, etc."> then the php script inserts the data into a MySQL database then returns a single pixel for the image, its VERY handy.

Posted: Sat May 31, 2003 6:26 pm
by pootergeist

Code: Select all

$file_ref = '/root/path/' .$_GET['file_ref'];
if(file_exists($file_ref))
	{
	$tipe = getimagesize($file_ref);
	$header_ext = ($tipe[2] < 4) ? ($tipe[2] < 3) ? ($tipe[2] < 2) ? ($tipe[2] < 1) ? NULL : 'gif' : 'jpeg' : 'png' : NULL;
	if($header_ext !== NULL)
		{
		header("Content-type: image/" .$header_ext);
		readfile($file_ref);
		}
	}
that should work for all allowable image types if called by
<img src="that_script.php?img_ref=image_name.image_ext" />