doudeng2057
2019-07-03 06:48
浏览 126
已采纳

XAMPP,PHP:echo为从数据库读取的blob添加了两个空格

I read blob (word 2010 document) from mysql database and store it in $data variable. When I simply store that data directly in PHP like so:

file_put_contents('c:\\temp\\dump.docx', $data);

I can open dump.docx in Word (size matches original file). If I attempt to send $data like this:

ob_start();
header('Content-disposition: attachment; filename=' . $name);
header('Content-type: ' . $type);
ob_clean();
echo $data;
ob_end_flush();
exit;

The stored file is two bytes longer. There are two spaces in front:

Downloaded word doc viewed in hex editor with two extra spaces in front

To check if I somehow do not output those spaces, I called ob_get_contents() just before echo and dumped content to a file. File has zero bytes. So it looks like echo is producing those two bytes.

图片转代码服务由CSDN问答提供 功能建议

我从mysql数据库中读取blob(word 2010文档)并将其存储在$ data变量中。 当我直接将这些数据直接存储在PHP中时:

  file_put_contents('c:\\ temp \\ dump.docx',$ data); 
   
 
 

我可以在Word中打开dump.docx(大小与原始文件匹配)。 如果我尝试发送这样的$ data:

  ob_start(); 
header('Content-disposition:attachment; filename ='。$ name); 
header(' 内容类型:'。$ type); 
ob_clean(); 
echo $ data; 
ob_end_flush(); 
exit; 
   
 
 

存储的文件是两个 字节更长。 前面有两个空格:

为了检查我是否以某种方式输出这些空格,我在回显之前调用了ob_get_contents()并将内容转储到文件中。 文件有零个字节。 看起来回声就是产生这两个字节。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • douci2015 2019-07-03 07:14
    最佳回答

    Here's post that helped me: https://drupal.stackexchange.com/questions/163628/extra-space-at-beginning-of-downloaded-image/163644

    ob_start was already called ealier. I needed to call only ob_clean() before sending content.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题