|
Posted by Koncept on 01/10/07 06:20
In article <1168327641.173650.214650@v33g2000cwv.googlegroups.com>,
kenoli <kenoli@igc.org> wrote:
> The problem is that I want send an id to the echo_image.php file so I
> can tell it which record to select the image from. When I set a
> session variable in the first file and try to retrieve it in the second
> file like this:
You don't need to set a session variable. You just need to adapt your
model of thinking slightly. Since you are effectively calling a PHP
page to generate your image, stop thinking about the resulting image,
and start thinking about the fact that you are working with PHP (
*hint* you can pass parameters! )
I have not validated this code, but the gist of it should be apparent.
<!-- ============ -->
<!-- = Page one = -->
<!-- ============ -->
<?php $id = 123456789; // some arbitrary integer identifier ?>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8"/>
<title>Testing image</title>
</head>
<body>
<img src="getimage.php?<?=$id?>" alt="Profile image" />
</body>
</html>
<!-- ========================== -->
<!-- = Page 2 :: getimage.php = -->
<!-- ========================== -->
<?php
// Start an output buffer
ob_start();
// Import whatever you need to here
require_once('dbStuff.php');
// Get the querystring
$id = $_SERVER['QUERY_STRING'];
// Check the querystring ( demo expects a number)
// IT IS IMPORTANT TO FILTER YOUR DATA
if( !is_numeric( $id ) )
trigger_error( "Bad ID value", E_USER_ERROR );
// Get the data from the DB...
$result = mysql_query("blah blah");
// clear the buffer
if(ob_get_length()) ob_clean();
// Send a new header ( depends on the mime type )
header("Content-type: image/jpg");
// Dump the image
echo $mysql_result($result,0);
// Stop processing
exit;
?>
--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche
Navigation:
[Reply to this message]
|