【问题标题】:How would I go about creating a php script to execute a shell command to write text to another php file?我将如何创建一个 php 脚本来执行 shell 命令以将文本写入另一个 php 文件?
【发布时间】:2012-05-20 02:01:11
【问题描述】:

我将如何创建一个 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

【问题讨论】:

  • 不知道你的意思,但是shell_exec("bash commands to want to use");会做的工作
  • 只是想知道,但你为什么要使用 shell 命令,因为在大多数情况下,fopen() - fwrite - fclose 会改为?

标签: php linux shell execute shell-exec


【解决方案1】:

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

【讨论】:

  • 同意,还要确保 shell_exec 不是您的 php.ini 文件中指定的 disabled function。对于一些共享托管服务提供商,确实如此。
猜你喜欢
  • 2012-07-02
  • 2013-12-26
  • 2018-09-19
  • 2013-05-28
  • 2023-03-10
  • 1970-01-01
  • 1970-01-01
  • 2014-03-02
  • 1970-01-01
相关资源
最近更新 更多