I have 2 problems I need help with. One is downloading a gzip file from a remote server. I created the function using fopen, and well it downloads the file, but when I go to open it, WinZip gives me the following: "The archive is either in unknown format or damaged." Here is the function I created:
<?php
function getstats($stats, $cachefile, $agelimit = 30, $timeout = 10) {
// convert agelimit to seconds
$agelimit *= 60;
$timestamp = @filectime($cachefile);
$age = time() - $timestamp;
if($age > $agelimit) {
$url = parse_url($stats);
$fp = fsockopen($url['host'], "80", &$errno, &$errstr, $timeout);
if (!$fp) return; //just quit on error
else {
$local = @fopen($cachefile, "w");
if (!$local) return; //just quit on error
fputs($fp, "GET " . $url['path'] . " HTTP/1.1\r\nHost: " . $url['host'] . "\r\n\r\n");
while(!feof($fp))
fwrite($local, fgets($fp, 128));
fclose($local);
}
}
}
?>
getstats("http://setiweb.ssl.berkeley.edu/stats/user.gz", "c:/temp/user.gz", 30, 60);
The second problem I am having, is that I am trying to unzip the file I downloaded with the script via PHP and am having no luck with it. Can anyone give help/advice/direction please? Thank you in advance. 🙂