I'm getting a gzipped File from an FTP Server that contains an xml. I want to gunzip it und write the xml as a file.
This is the code I'm using right now:
ftp_get($ftpCon, __DIR__."/../files/data.gz", $val, FTP_BINARY);
$srcName = __DIR__."/../files/data.gz";
$dstName = __DIR__."/../files/stuff.xml";
$command = 'gunzip -c '.$srcName.' > '.$dstName;
$escapedCommand = escapeshellcmd($command);
system($escapedCommand);
But the XML File will be printed out on the console and not written into a file. How can I write the data from the zipped file into an XML file?
The problem lies in your use of escapeshellcmd
. If you look at this example, you'll see that your escaped command looks like this:
gunzip -c from/data.gz \> to/stuff.xml
But you don't want the >
to be escaped. Since you have full control over the rest of the command, try escaping only the filenames (you don't have to if they're hard-coded like in your example).
Use the zlib extension: