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 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler