Re: displaying image from MySQL DB using HTML/PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 3/13/07, Bruce Gilbert <webguync@xxxxxxxxx> wrote:
I am having some difficulty getting an image to display on a php that
I have added to MySQL DB.

Here is what I have tried so far....

in the MySQL DB I have a table called image_holder and the fields are
id,mimename,filecontents...filecontents field is set to a type of blob
using PHPMyAdmin and I have uploaded the image in MySQL.

In the PHP code I have:

[php]
 <?php
$dbhost = 'hostaddress';
$dbuser = 'username';
$dbpass = 'password;
$dbcnx = @mysql_connect($dbhost,$dbuser,$dbpass);

if (!$dbcnx)
{
echo( "connection to database server failed!");
exit();
}
if (! @mysql_select_db("image_holder") )
{
echo( "Image Database Not Available!" );
exit();
}

$img = $_REQUEST["img"];

$result = @mysql_query("SELECT * FROM images WHERE id=" . $img . "");

if (!$result)
{
echo("Error performing query: " . mysql_error() . "");
exit();
}
while ( $row = @mysql_fetch_array($result) )
{
$imgid = $row["id"];
$encodeddata = $row["mimetype"]; // Why pass the mimetype $encodeddata?
$title = $row['filecontents']; // And why pass the contents of the file to $title?
}

?>

So you just need to set the content-type and output
add this to the bottom of the script:
header("Content-Type: ".$encodeddata);
echo $title;

If i understand you right.

Tijnema


and in the HTML code

<center><img src="image.php?img=1" width="200" border="1" alt=""></center>

I am probably way off base, so need some help!


--
::Bruce::

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux