Helping ordinary people create extraordinary websites!

Go Back   Web Development Forum > Website Programming > Server-Side Scripting
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-08-2006, 06:07 AM
Junior Member
 
Join Date: Oct 2006
Posts: 1
Default database image problem

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
sql: search multiple keywords for one image md_doc Database Development 1 01-09-2008 12:08 PM
Image load on mouseover of another image Dezynincodr Client-Side Scripting 4 12-13-2007 11:38 PM
database connection error dharshini Database Development 1 12-08-2007 08:25 PM
array related problem in asp meena1977 Server-Side Scripting 1 12-05-2007 12:31 PM
problem with mysql and php dharshini Server-Side Scripting 1 07-25-2007 02:43 AM


All times are GMT -5. The time now is 01:58 AM.


Website Design by Ducani Media Group
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.