I just tried it, and it works. You can see it working here:
http://www.nuhit.com/test/getavatar.php?userid=86
Here is my full code: (you would need to change the location of your forums in the config_filename variable).
PHP Code:
$config_filename = dirname(__FILE__) . "/../forums/includes/config.php";
require_once $config_filename;
define( 'TABLE_PREFIX', $config['Database']['tableprefix'] );
$userid = $_REQUEST['userid'];
$conn = mysql_connect( $config['MasterServer']['servername'], $config['MasterServer']['username'], $config['MasterServer']['password'] );
if (!$conn)
die ("Could not connect to server.");
if (!mysql_select_db( $config['Database']['dbname'], $conn ))
die ("Database not found.");
$sql = "SELECT filedata, dateline, filename
FROM " . TABLE_PREFIX . "customavatar
WHERE userid = $userid";
$results = mysql_query($sql, $conn);
if (!$results)
die ("Error running query.");
$row=mysql_fetch_array($results);
header('Cache-control: max-age=31536000');
header('Expires: ' . gmdate('D, d M Y H:i:s', (TIMENOW + 31536000)) . ' GMT');
header('Content-disposition: inline; filename=' . $row['filename']);
header('Content-transfer-encoding: binary');
header('Content-Length: ' . strlen($row['filedata']));
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $row['dateline']) . ' GMT');
$extension = trim(substr(strrchr(strtolower($row['filename']), '.'), 1));
if ($extension == 'jpg' OR $extension == 'jpeg')
header('Content-type: image/jpeg');
else if ($extension == 'png')
header('Content-type: image/png');
else
header('Content-type: image/gif');
echo $row['filedata'];