你好我使用下面的代码下载从服务器检索.zip文件,我确实得到了文件,但我试图将其解压缩到同一个php文件中的文件夹中,但是当我运行我的脚本时下载文件,然后这是我得到的输出:
这是我得到的输出:
File Opening Successful
Warning: ZipArchive::extractTo() [ziparchive.extractto]: Invalid or unitialized Zip object in /home/content/38/10376438/html/viptravelink/xml/xml3.php on line 48
Warning: ZipArchive::close() [ziparchive.close]: Invalid or unitialized Zip object in /home/content/38/10376438/html/viptravelink/xml/xml3.php on line 49
Uncompression Successful
这是我正在使用的脚本:
<?php
/*
* XML Sender/Client.
*/
$xmlRequest = '<?xml version="1.0" encoding="utf-8"?>
<Request> <Source><RequestorID Client="***" EMailAddress="xml@***.com" Password="***" /> <RequestorPreferences Language="en" Currency="USD"> <RequestMode>SYNCHRONOUS</RequestMode> </RequestorPreferences> </Source> <RequestDetails> <ItemInformationDownloadRequest ItemType="hotel">
<IncrementalDownloads>
</IncrementalDownloads>
</ItemInformationDownloadRequest> </RequestDetails></Request>';
// We send XML via CURL using POST with a http header of text/xml.
$url = 'https://interface.demo.gta-travel.com/rbsusapi/RequestListenerServlet';
$ch = curl_init();
$zipPath = '/home/content/38/10376438/html/viptravelink/xml/' .date('m-d-Y_h-i-s'). '.zip';
$out = fopen($zipPath, 'wb');
echo "File Opening Successful<br>";
if ($out == FALSE){
echo "Download Failed<br>";
exit;
}
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_SSLVERSION, 3); // Force SSLv3 to fix Unknown SSL Protocol error
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_FILE, $out);
curl_setopt( $ch, CURLOPT_POSTFIELDS,$xmlRequest );
curl_setopt($ch,CURLOPT_ENCODING , "gzip");
curl_setopt($ch,CURLOPT_AUTOREFERER , 1);
curl_setopt($ch,CURLOPT_MAXREDIRS , 10);
curl_setopt($ch, CURLOPT_HEADER, 1);
$result=curl_exec($ch);
$httpCode = curl_getinfo($ch);
curl_close($ch);
fclose($out);
$zip = new ZipArchive;
if (!$zip) {
echo "Could not make ZipArchive object.<br>";
exit;
}
$zip->open('$zipPath');
$zip->extractTo('/home/content/38/10376438/html/viptravelink/xml/content/');
$zip->close();
echo "Uncompression Successful<br>";
?>
非常感谢任何帮助!!
谢谢!
答案 0 :(得分:0)
您的zip->open('$zipPath');
$ zipPath变量未初始化,并且您将变量包含在单引号内且不会扩展变量put将文字值作为文件名。此外,您将CURLOPT_HEADER
设置为1将使输出包括标题,从而导致文件无效。解决问题。将CURLOPT_HEADER
设置为0并设置zip->open($zipPath);