I am using curl to down load a zip file and I am
then trying to unzip it, but I don't think that I am
using the functions properly because I get warnings
This is my code:
-
<?php
-
-
if (!extension_loaded('zip')) {
-
dl('zip.so');
-
}
-
-
$func_path = "/home/guru54gt5/public_html/im/my_functions.php";
-
require_once("$func_path");
-
-
$target_url = "http://www.support-focus.com/test_map.zip";
-
$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
-
-
echo "<br>Starting<br>Target_url: $target_url<br><br>";
-
-
// make the cURL request to $target_url
-
$ch = curl_init();
-
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
-
curl_setopt($ch, CURLOPT_URL,$target_url);
-
curl_setopt($ch, CURLOPT_FAILONERROR, true);
-
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
-
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
-
curl_setopt($ch, CURLOPT_BINARYTRANSFER,true);
-
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
-
$page = curl_exec($ch);
-
if (!$page) {
-
echo "<br />cURL error number:" .curl_errno($ch);
-
echo "<br />cURL error:" . curl_error($ch);
-
exit;
-
}
-
curl_close($ch);
-
-
// Un zip the file
-
-
$zip = new ZipArchive;
-
if (! $zip) {
-
echo "Could not make ZipArchive object.";
-
exit;
-
}
-
$zip->open("$page");
-
$zip->extractTo('./');
-
$zip->close();
-
echo "Ok!";
-
?>
-
-
The errors I get are in fact warnings:
Warning: ZipArchive::extractTo() [function.ZipArchive-extractTo]: Invalid or unitialized Zip object in /home/guru54gt5/public_html/sys/convert_xml_no1.php on line 40
Warning: ZipArchive::close() [function.ZipArchive-close]: Invalid or unitialized Zip object in /home/guru54gt5/public_html/sys/convert_xml_no1.php on line 41
Ok!
Line 40 and 41 are:
-
$zip->extractTo('./');
-
$zip->close();
The script is here:
test script
Is the problem because my $page is not a file ?
I am a bit confused about this so would appreciate some help.
Thanks.