wget 在使用 php 执行时不起作用

wget its not working when executing with php

我有这个小php代码

$command = 'bash newpdftoebook.bash ' . $_POST['BookID'] . ' "' . $_POST['pdffile'] . '"';
$descriptorspec = array(
    // stdin is a pipe that the child will read from
    0 => array("pipe", "r"),
    // stdout is a pipe that the child will write to
    1 => array("pipe", "w"),
    // stderr is a pipe that the child will write to 
    2 => array("pipe", "w")
);
flush();
$process = proc_open($command, $descriptorspec, $pipes, realpath('./'), array());

这是我的 bash 文件

dirhome=/var/www/html/
dirprocessing=$dirhome"processing/"
if [ ! -d "$dirprocessing" ]; then
  echo -e "Error: there is no folder 'processing'"
fi

pdffile=$dirprocessing"action-"".pdf"
if [ ! -f "$pdffile" ]; then 
  #clear dirftp
  rmdir=$dirprocessing"*"
  rm -R $rmdir
  #copy from google drive to local ubuntu server *.pdf 
  wget -O $dirprocessing"action-.pdf" ""
fi

不是下载文件,但是当我在终端中执行它时,文件下载成功。我 运行 在我的终端里

bash /var/www/html/newpdftoebook.bash 2569 "http://kmmc.in/wp-content/uploads/2014/01/lesson2.pdf"

我做错了什么,顺便说一句,这段代码在那之前工作正常,但我安装了一台新的 Ubuntu 18 机器并将代码移到那里,从那以后代码就不再工作了。我也已经在机器上安装了 wget,因为我已经对其进行了测试,并且它正在从终端运行。

感谢 Mike Q,我弄清楚了 wget 无法工作的原因。原来这是一个权限问题。我只需要将文件夹所有者更改为 www-data,在我的例子中是 运行 apache2 服务器并执行 php 脚本,因为该文件夹是 root 用户的所有者。要找出哪个用户是 运行 apache2 服务(99% 是 www-data),你可以检查这个 link 或者在 php

中执行这个脚本
echo shell_exec('whoami');

之后只需转到主文件夹并在终端中使用此命令更改权限

$ sudo chown -R www-data:www-data [folder-name]