download2014711 2018-11-21 06:23
浏览 133
已采纳

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 2018-12-11 05: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]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部