如何删除警告无法修改标头信息 - 已发送的标头

时间:2014-08-10 09:43:27

标签: php

出现“已发送标头”警告。我关闭$zip->close();但仍显示警告

$zip = new ZipArchive;
$download = 'new_zip.zip';
$zip->open($download, ZipArchive::CREATE);
foreach (glob("zipfile/*") as $file) { 
    $zip->addFile($file);
}
$zip->close();
header('Content-Type: application/zip');
header("Content-Disposition: attachment; filename = $download");
header('Content-Length: ' . filesize($download));
header("Location: $download");

1 个答案:

答案 0 :(得分:1)

在脚本开头,使用:

<?php ob_start(); ?>

然后在脚本的末尾添加:

<?php ob_flush(); ?>