gpt4 book ai didi

php - 从另一个站点下载文件并添加到 zip

转载 作者:搜寻专家 更新时间:2023-10-31 22:10:53 25 4
gpt4 key购买 nike

另一个网站上有一些 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);

?>

最佳答案

尝试从此行中删除扩展名:

header("Content-Disposition: attachment; filename=\"".$filename."\";");

您已经在(代码的)第二行设置了文件扩展名。

关于php - 从另一个站点下载文件并添加到 zip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13133705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com