
October 30th, 2012, 01:31 AM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 1
Time spent in forums: 4 m 33 sec
Reputation Power: 0
|
|
|
PHP5 - Retrieve file from another site and zip it
HI GUys,
Noob here.. some help is very much appreciated. 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>\n");
}
$file=/* some URL address hosting this csv file*/".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);
?>
|