Interestingly enough, I was using an include file for dbnames, etc., but no matter what I tried, I kept getting some sort of output prior to issuing a header when I was writing a script to read an image out of a database.
I would swear that there were/are no extra spaces, lines, etc., in the include file, but I still couldn't get it to work.
This works.
<?php
ob_start(); // turn output buffering on
// open the database and retrieve the record
(!($dbh=mysql_connect ("localhost",
"hard-coded-username",
"hard-coded-password")));
(!mysql_select_db("hard-coded-database",$dbh));
$query = "SELECT thumbnail FROM thumbs
WHERE thumbid = $thumb";
(!($result = @ mysql_query ($query, $dbh)));
$data = @mysql_fetch_array($result);
$image = $data["thumbnail"];
header("Content-Type: image/jpeg");
echo $image;
ob_end_flush();
?>
but this does not work (get's a big red x)... using your include as the example.
<?php
include (config.php);
ob_start(); // turn output buffering on
// open the database and retrieve the record
(!($dbh=mysql_connect ("$db_host",
"$db_user",
"$db_pass")));
(!mysql_select_db("$db_name",$dbh));
$query = "SELECT thumbnail FROM thumbs
WHERE thumbid = $thumb";
(!($result = @ mysql_query ($query, $dbh)));
$data = @mysql_fetch_array($result);
$image = $data["thumbnail"];
header("Content-Type: image/jpeg");
echo $image;
ob_end_flush();
?>
I just gave up trying to make it work. But, as a rule, I like includes.