有几个csv文件托管在另一个网站上,我正在尝试检索它们并将它们打包成zip文件进行下载。压缩似乎起作用了,但是打包文件总是为空。任何帮助都非常感谢...顺便说一下,这是PHP语言。
<?php
$zip = new ZipArchive();
$filename = "test114.zip";
$numParts = count($file_names);
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE)
{
exit("cannot open <$filename>\n");
}
$file="http://ichart.finance.yahoo.com/table.csv?s=YHOO&d=9&e=25&f=2012&g=d&a=0&b=3&c=2000&ignore=.csv";
$filedata = fopen ($file, "r");
$contents = fread($filedata, filesize($file));
$zip->addFile($filedata, "file1");
fclose($filedata);
$zip->close();
header('Content-Type: application/zip');
header("Content-Disposition: attachment; filename=\"".$filename."\".zip;");
header('Content-Length: ' . filesize($filename));
readfile($filename);
?>