我正在尝试在ZF2&中下载文件卡在某处。我无法得到解决方案。该文件是正确的&可读。我认为标题设置存在问题。请帮忙!。摘录代码如下:
$response = new \Zend\Http\Response\Stream();
$response->setStream(
fopen($filePath, 'r')
);
$response->setStatusCode(200);
$headers = new \Zend\Http\Headers();
$headers->addHeaderLine('Content-Type', 'application/octet-stream');
$headers->addHeaderLine('Content-Transfer-Encoding','binary');
$headers->addHeaderLine('Content-Type', 'application/octet-stream');
$headers->addHeaderLine(
'Content-Disposition', 'attachment; filename="' . $media->getName() . '"'
)
->addHeaderLine(
'Content-Length', filesize($filePath)
);
$response->setHeaders($headers);
return $response;
我提到了以下内容: force download using ZF2 &安培; Zend Framework 2 - Rendering CSV data
我收到了损坏的文件
答案 0 :(得分:0)
您似乎有两个重复的标题:
$headers->addHeaderLine('Content-Type', 'application/octet-stream');