简体   繁体   English

从MySQL DB PHP下载空的BLOB文件

[英]Download empty BLOB file from MySQL DB PHP

I'm trying to download a XML file from my DB. 我正在尝试从数据库中下载XML文件。 The file is stores in a BLOB field, but when I open the page it dowloads a blank xml file. 该文件存储在BLOB字段中,但是当我打开页面时,它会下载一个空白的xml文件。
This is my function: 这是我的功能:

<?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;
?>

Does anyone have any idea? 有人有什么主意吗?

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

$xml is your actual xml data, it's NOT a filename, so filesize() will FAIL and return boolean FALSE. $xml是您的实际xml数据,它不是文件名,因此filesize()失败并返回布尔值FALSE。 You cannot get the size of a file which does not exist. 您无法获取不存在的文件的大小。

Try 尝试

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

instead. 代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM