dongqidi2799 2014-11-25 09:42
浏览 70
已采纳

PHP:从gunzip写入文件

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?

  • 写回答

2条回答 默认 最新

  • drsw9390405 2014-11-25 09:52
    关注

    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).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?