download2014711 2018-11-21 14:23
浏览 132
已采纳

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 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]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)