【发布时间】:2019-03-06 14:22:20
【问题描述】:
我成功生成了一个用于谷歌地球的 xml 文件。 当我打开文件时,它看起来像这样。文件从第 1 行开始Xml generated
然后我生成一个链接供用户下载文件。这些文件现在从第 2 行开始。 File download from the link.
我不明白为什么会这样。 这是我用来将文件发送给用户的代码。
$target_file = "../files/google.xml";
$fh = fopen($target_file, 'r');
$file_stream = new Stream($fh);
return $response ->withHeader('Content-Type', 'application/xml; charset=utf-8')
->withHeader('Content-Type', 'application/force-download')
->withHeader('Content-Type', 'application/download')
->withHeader('Content-Description', 'File Transfer')
->withHeader('Content-Disposition', 'attachment; filename="' . basename($target_file) . '"')
->withHeader('Expires', '0')
->withHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
->withHeader('Pragma', 'public')
->withBody($file_stream);
有人可以告诉我为什么会这样吗?
【问题讨论】: