从 MySQL DB PHP 下载空的 BLOB 文件

Download empty BLOB file from MySQL DB PHP

我正在尝试从我的数据库下载 XML 文件。该文件存储在 BLOB 字段中,但当我打开该页面时,它会下载一个空白 xml 文件。
这是我的功能:

<?php 
    $conexao = mysql_connect("db","user","pss") or die('Not connected : ' . mysql_error());
    mysql_select_db("db", $conexao) or die (mysql_error());
    $result = mysql_query("select * from xmlNFe where xml_id = 1", $conexao);
    $row = mysql_fetch_array($result);
    $xml =  $row['xml_xml'];
    $nome = mysql_result($result, 0, 'xml_chNFe');

    header('Content-type: application/octet-stream');
    header('Content-Description: File Transfer');
    header("Pragma: public");
    header("Content-Disposition: attachment;filename=".$nome.".xml"); 
    header('Content-Transfer-Encoding: binary');
    header("Content-length: ".filesize($xml));
    header('Accept-Ranges: bytes');
    ob_clean();
    flush();
    echo $xml;
    mysql_close($conexao);
    exit;
?>

有人知道吗?

header("Content-length: ".filesize($xml));
                                   ^^^^

$xml 是您的实际 xml 数据,它不是文件名,因此 filesize()FAIL 和 return 布尔值错误的。您无法获取不存在的文件的大小。

尝试

header("Content-length: ".strlen($xml));
                          ^^^^^^

相反。