douping4436 2012-10-30 06:22
浏览 43

从其他站点下载文件并添加到zip中

There are a few csv files hosted on another website n i'm trying to retrieve them and package into a zip file to download. Zipping seems to work but the package is always empty. Any help is very much appreciated... This is in PHP by the way.

<?php

$zip = new ZipArchive();
$filename = "test114.zip";
$numParts = count($file_names);
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) 
{
    exit("cannot open <$filename>
");
}



$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);

?>
  • 写回答

2条回答 默认 最新

  • dongshao9106 2012-10-30 06:49
    关注

    Try to remove the extension from this line:

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

    You already set the filename extension on second line (of code).

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么