You are here: Image issues « All PHP « IT news, forums, messages
Image issues

Posted by kenoli on 01/09/07 07:27

I am trying to retrieve an image stored in a blob field in a database
and display it in an html document. I call it into the file where I
want to display it using the following code:

<?php echo '<img src="echo_image.php" title="Personal Thumbnail."
alt="No image available.">';?>

The file echo_image.php contains the following code:

<?php
$tid = '18';

// Connect to the database
require_once ('../includes/scripts/mysql_connect_bh.php');

// Create the query
$sql = "SELECT image FROM tbl_person WHERE person_id=$tid";

// Query the database
$result = mysql_query("$sql") or die("Invalid query: " .
mysql_error());

// Send header
header("Content-type: image");

// Echo the image
echo mysql_result($result, 0);

?>

This works fine. The image is placed in my original document,

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:

<?php
session_start();

$_SESSION['id'] = 18;

php echo '<img src="echo_image.php" title="Personal Thumbnail."
alt="No image available.">';
?>

<?php
$tid = $_SESSION['id'];

// Connect to the database
require_once ('../includes/scripts/mysql_connect_bh.php');

// Create the query
$sql = "SELECT image FROM tbl_person WHERE person_id=$tid";

// Query the database
$result = mysql_query("$sql") or die("Invalid query: " .
mysql_error());

// Send header
header("Content-type: image");

// Echo the image
echo mysql_result($result, 0);

?>

I get an error saying "no image available.

How can I send an id value from the first file to the second so that I
can indicate which record to retrieve the image from?

Is there some other way to do this?

Also, why doesn't the following code work in the second file. When I
do this, the image data gets returned rather than the interpreted
image.

<?php
require_once ('../includes/scripts/mysql_connect_bh.php');

$tid = '18';

// Create the query
$sql = "SELECT image FROM tbl_person WHERE person_id=$tid";

// Query the database
$result = mysql_query("$sql") or die("Invalid query: " .
mysql_error());

$row = mysql_fetch_array($result, MYSQL_ASSOC);

// Send header
header("Content-type: image");
echo $row['image'];

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация