Note that the userid is numeric, you don't need the quotes (it should work with the quotes, but you are making MySQL do an extra conversion for each row.)
Try the following code, I haven't tried but it should work.
PHP Code:
$sql = mysql_query("SELECT filedata, dateline, filename FROM vb_customavatar WHERE userid = 1");
$row=mysql_fetch_array($sql);
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');