-2

I have used and tried below code for getting the xml file from FTP server, Actually that xml file is zipped as accommodation.xml.zip. So that I couldn't get that xml file using curl() in php

$url_method = "ftp://ftp.example.com/accommodation.xml.zip";
$username = "test";
$pwd = "test";

   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $url_method);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_USERPWD, "$username:$pwd");    
   $xmlcontent = gzdecode ( curl_exec($ch) ); 
   curl_close($ch);
   print_r($xmlcontent);

By using this code, I have got below error: ////////////////////////// Severity: Warning

Message: gzdecode(): data error

Filename: controllers/cron.php

Line Number: 438 /////////////////////////

But when I try to use the ftp url in browser, that zip file has downloaded.

Can anyone help me to get the xml file using curl() without error ?

user3184378
  • 105
  • 1
  • 1
  • 6

1 Answers1

1

gzdecode() does not unzip files. It decodes different but similarly named files called gzip or gz files. This is why the function reports a data error.

You will have to use the PHP Zip Functions instead to extract and read the XML files from the zip. You can find use examples for the PHP Zip functions here.

Indrajeet
  • 5,490
  • 2
  • 28
  • 43
Tryth
  • 411
  • 2
  • 11
  • I want to print the xml content from zip file, can you tell me the exact function for extract & display the xml file from FTP server – user3184378 Dec 13 '14 at 11:54