download2014711
2018-11-21 14:23 阅读 113
已采纳

wget在使用php执行时无效

I have this small php code

$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());

And this is my bash file

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

pdffile=$dirprocessing"action-"$1".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-$1.pdf" "$2"
fi

It is not downloading the file, but when i execute it within the terminal the file is downloaded successfully. I am running this inside my terminal

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

What i am doing wrong, btw this code was working fine before that, but i installed a new Ubuntu 18 machine and moved the code there and since then the code dosent work anymore. Also i have installed wget on the machine as i have test it and it is working from terminal.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    doubi8383 doubi8383 2018-12-11 13:35

    Thanks to Mike Q I figure out why wget was not working. It turn out it was a permission issue. I just had to change the folder owner to www-data which in my case was running the apache2 server and executing the php script, because that the folder was owner by root user. To find out which user is running apache2 service (in 99% it is www-data) you can check this link or just execute this script in php

    echo shell_exec('whoami');
    

    after that just go to the main folder and just change the rights with this command in the terminal

    $ sudo chown -R www-data:www-data [folder-name]
    
    点赞 评论 复制链接分享

相关推荐