I’m getting myself a little confused about this.
Here is how I am doing it for a ZIP file:
Download cURL function:
function grab_file($url, $new_file) {
//get file
$ch = curl_init();
$fp = fopen("zip/$new_file", "w");
$options = array(CURLOPT_URL => $url, CURLOPT_HEADER => 0, CURLOPT_FAILONERROR =>
1, CURLOPT_AUTOREFERER => 1, CURLOPT_BINARYTRANSFER => 1, CURLOPT_RETURNTRANSFER =>
1, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_TIMEOUT => 5, CURLOPT_ENCODING => 1,
CURLOPT_FILE => $fp);
curl_setopt_array($ch, $options);
$file = curl_exec($ch);
curl_close($ch);
fclose($fp);
if (!$file) {
return false;
} else {
return true;
}
}
The unzip function:
function get_zip($data) {
$zip = new ZipArchive();
$filename = $data;
if ($zip->open($filename, ZIPARCHIVE::CREATE || ZIPARCHIVE::OVERWRITE)) {
$zip->extractTo('feeds');
$zip->close();
return true;
} else {
return false;
}
}
I’m getting myself confused about the Zlib functions http://www.php.net/manual/en/ref.zlib.php
Unlike zip, these functions read it to memory, right?
So would I have to create some code like below and then create a XML or CVS file out of the PHP array?
$zd = gzopen($gz_file, "r");
$data = gzread($zd, 1000000);
gzclose($zd);
if ($data !== FALSE) {
return $data;
} else {
return FALSE;