ZipArchive PHP-尽管到目前为止遵循了stackoverflow的每一个答案,但仍不断出现错误

ZipArchive PHP-尽管到目前为止遵循了stackoverflow的每一个答案,但仍不断出现错误,php,ziparchive,Php,Ziparchive,我使用MySQL查询创建了一个文件。现在正试图下载它作为一个zip。我想包括第二个文件,但我甚至不能让一个工作 温拉只是失败了。在另一个windows系统上,我收到一个错误,说存档是空的,即使文件\u存在 $file = '/temp/' . $temp_filename; if(file_exists($file)) { $zipname = 'myfile_' . $name . '_' . $date . '.zip'; $zip = new

我使用MySQL查询创建了一个文件。现在正试图下载它作为一个zip。我想包括第二个文件,但我甚至不能让一个工作

温拉只是失败了。在另一个windows系统上,我收到一个错误,说存档是空的,即使
文件\u存在

$file = '/temp/' . $temp_filename;
if(file_exists($file)) {
            $zipname = 'myfile_' . $name . '_' . $date . '.zip';
            $zip = new ZipArchive;
            $zip->open($zipname, ZipArchive::CREATE);
            $download_file = file_get_contents($file);
            $zip->addFromString(basename($file),$download_file);
            $zip->close();

            // also tried $zip->addFile($file,basename($file));


            //header('Content-Description: File Transfer');
            header('Content-Type: application/zip');
            header('Content-Disposition: attachment; filename='.basename($zipname));
            //header('Content-Transfer-Encoding: binary');
            //header('Expires: 0');
            //header('Cache-Control: must-revalidate');
            //header('Pragma: public');
            header('Content-Length: ' . filesize($zipname));
            header('Pragma: no-cache');
            header('Expires: 0');
            ob_clean(); // also tried commenting this
            flush(); // and this
            readfile($zipname);
            // exit(); // tried with and without exit.
}


Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Disposition:attachment; filename=test.zip
Content-Type:application/zip
Date:Sat, 28 Feb 2015 01:04:57 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=5, max=100
Pragma:no-cache
Server:Apache/2.4.7 (Ubuntu)
Transfer-Encoding:chunked
X-Powered-By:PHP/5.5.9-1+sury.org~precise+1

ZipArchive::如果文件存在,创建将失败,请尝试:

$zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);

启用错误报告,请首先根据CLI进行尝试,以查看它是否有任何作用。
wget-s
显示了什么?显示任何结果zip的hextump。@mario I从google chrome添加了标题。那有帮助吗。我会试着去倒垃圾。我得用谷歌搜索一下。