Hi there,
I used a piece of code from this website by
Darren W. Hedlund to store images into a database and to view the images from the database later.
All works fine, but for security reasons i want to put my database login and password in a seperate file and then use "require" to use the data (I've been doing this a lot and it works all the time).
When i add the line: require($_server["DOCUMENT_ROOT"]."cgi-bin/db_config.php");
the script seems to work, the outline of the image shows but the image itself doesn't, there's only the little red cross.
So somehow the it is able to read the image x and y size (because the outline has the correct size) but the actual image data gets lost somewhere.
So in a nutshell it comes down to this:
This works:
<?php
$dbcnx = @mysql_connect("host","username", "password");
if (!$dbcnx)
{
echo( "connection to database server failed!" );
exit();
}
if (! @mysql_select_db("dbname") )
{
echo( "Image Database Not Available!" );
exit();
}
$img = $_REQUEST["img"];
$result = @mysql_query("SELECT * FROM images WHERE imgid='$img'");
if (!$result)
{
echo("Error performing query: " . mysql_error() . "");
exit();
}
while ( $row = mysql_fetch_array($result) )
{
$imgid = $row["imgid"];
$encodeddata = $row["sixfourdata"];
}
echo base64_decode($encodeddata);
?>
<html>
<body>
<img src='image.php?img=1' border="0" alt="">
</body>
</html>
This doesn't work
<?php
require($_server["DOCUMENT_ROOT"]."cgi-bin/db_config.php");
$dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass);
if (!$dbcnx)
{
echo( "connection to database server failed!" );
exit();
}
if (! @mysql_select_db("dbname") )
{
echo( "Image Database Not Available!" );
exit();
}
$img = $_REQUEST["img"];
$result = @mysql_query("SELECT * FROM images WHERE imgid='$img'");
if (!$result)
{
echo("Error performing query: " . mysql_error() . "");
exit();
}
while ( $row = mysql_fetch_array($result) )
{
$imgid = $row["imgid"];
$encodeddata = $row["sixfourdata"];
}
echo base64_decode($encodeddata);
?>
<html>
<body>
<img src='image.php?img=1' border="0" alt="">
</body>
</html>
It's probably something realy stupid but don't have a clue...
HELP!!
Regards
Robert Thiemann.