我将如何创建一个 php 脚本来执行 shell 命令以将文本写入另一个 php 文件


How would I go about creating a php script to execute a shell command to write text to another php file?

我将如何创建一个php脚本来执行shell命令以将文本写入另一个php文件? 并且没有任何 sudo 问题。到目前为止,我有这个。

<?php
include("inc/config.php");
$command = "sed -i '$ a'this is line 2 without redirection' admin.php";
$command1 = "cat admin.php";
$output = shell_exec($command);
$output1 = shell_exec($command1);
echo "<pre>$output</pre>";
echo "<pre>$output1</pre>";
?>

我使用了chown wwwdata和chmod 777

您的脚本需要在有权执行您需要执行的所有操作的帐户下运行。 就是这么简单。