calling exec on a php file and passing parameters?

前端 未结 5 1676
慢半拍i
慢半拍i 2021-02-19 00:53

I am wanting to call a php file using exec.

When I call it I want to be able to pass a variable through (an id).

I can call echo exec(\"php /var/www/unity/

5条回答
  •  长情又很酷
    2021-02-19 01:19

    this adapted script shows 2 ways of passing parameters to a php script from a php exec command: CALLING SCRIPT

     /var/www/ztest/log01.txt 2>&1 &");
    
    echo "ended the calling script"; 
    ?>
    

    CALLED SCRIPT

     
    

    dont forget to verify execution permissions and to create a log01.txt file with write permissions (your apache user will usually be www-data).

    RESULT

    argv params: Array

    (

    [0] => /var/www/ztest/helloworld.php
    
    [1] => 12
    
    [2] => target=13
    

    )

    got the size right, wilburargv element 1: 12

    choose whatever solution you prefer for passing your parameters, all you need to do is access the argv array and retrieve them in the order that they are passed (file name is the 0 element).

    tks @hakre

提交回复
热议问题