【发布时间】:2015-11-10 06:41:36
【问题描述】:
我正在尝试从我的数据库中下载一个 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;
?>
有人知道吗?
【问题讨论】:
-
为什么要使用 fetch_array() AND result()?你已经获取了一行,为什么不直接
$nome = $row['xml_chNfe']?
标签: php mysql file download blob