[英]How to execute sh file by PHP from web page
echo 'test';
<?php
echo 'start'.PHP_EOL;
echo shell_exec('/bin/sh /root/script/test.sh');
echo 'end'.PHP_EOL
如果我在本地php sh.php
運行PHP,則start test end
,但是如果我從url http://example.com/sh.php
運行php,則只能start end
,則腳本不會執行,但是如果我執行echo shell_exec('ls -al');
,它將顯示網頁上的列表。
使用file_get_contents
嘗試一下:
$path = file_get_contents('/root/script/test.sh');
echo shell_exec($path);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.