gpt4 book ai didi

php - 使用 PHP 输出二进制数据时出错

转载 作者:可可西里 更新时间:2023-11-01 01:07:21 27 4
gpt4 key购买 nike

我写了一个简单的 php 来从数据库加载一些二进制数据,然后输出到客户端。

    $sql="select FightPlayEnd from ZMTXLogic.FightLog where ID=".addslashes($id);
$result=$db->query($sql);

if($db->num_rows($result)>0)
{

$row = mysql_fetch_assoc($result);
$nByteCount = mb_strlen($row["FightPlayEnd"], '8bit');
//echo $nByteCount;

header("Content-type:application/octet-stream");
header("Accept-Ranges:bytes");
header("Accept-Length:".$nByteCount);
header("Content-Disposition:attachment;filename=FightPlayEnd.bin");
header( "Content-type: application/octet-stream");

echo $row["FightPlayEnd"];
}

问题是从 IE 中获取的数据与原始二进制数据不同,而是添加了EF BB BF(在 UltraEdit 中查看)在标题处,0D 0A 0D 0A 在结尾处。有什么问题吗?

最佳答案

0D 0A 0D 0A就是\r\n\r\n,也就是两个换行符。

EE BB BF 是一个字节序标记。它表示 UTF-8 编码。

编辑(见评论):

您的脚本可能会输出超出应有的输出(尤其是那些 \r\n\r\n)。

您需要在开始输出数据之前清理输出缓冲区 (ob_clean()) 并在回显后立即退出。

关于php - 使用 PHP 输出二进制数据时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7830505/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com