代码之家  ›  专栏  ›  技术社区  ›  Jfonts

从exec()或shell_exec(

  •  3
  • Jfonts  · 技术社区  · 8 年前

    我正在尝试将我编写的wget命令集成到php脚本中。该命令递归地下载网站上的每个html/php文件(这是我在file_get_contents()中没有找到的必需功能)。我已经在终端窗口中测试了wget命令,但当使用exec()或shell_exec(。我没有收到任何错误或警告。

    这是有问题的命令,

    wget --recursive -m --domains oooff.com --page-requisites --html-extension --convert-links -R gif,jpg,pdf http://www.oooff.com/
    

    我尝试过exec()和shell_exec(”)中的简单wget命令(没有那么多参数),但它们也不起作用。

    如果wget不是一个选项,我愿意使用其他方法下载整个网站。

    我现在的代码是,

    exec("wget google.com", $array);
    

    然后在打印阵列时它是空的

    3 回复  |  直到 8 年前
        1
  •  2
  •   Jfonts    8 年前

    我必须指定wget的路径。新命令:

    exec("/usr/local/bin/wget google.com", $array);
    
        2
  •  1
  •   user4466350 user4466350    8 年前

    使用适当的选项调用wget

    -q to remove it s information output
    -O - to output the request response on stdout
    
    php -r 'exec("wget -q -O - google.com", $array);var_dump($array);'
    
        3
  •  0
  •   vladkras    8 年前

    在我们的案例中 wget 没有足够的权限将wget'ed文件保存在当前目录中。解决方案:

    $dir = __DIR__.'/777folder/';
    exec("/usr/bin/wget -P ".$dir." --other-options");
    

    哪里

    -P,  --directory-prefix=PREFIX  save files to PREFIX/...
    

    附言。我们还添加了 /usr/bin 使用找到 whereis wget 但在我们的系统中,没有它就可以正常工作