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 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试