使用php在web中使用sh文件删除文件



hi我有一个php文件,有两个按钮来执行sh文件,在sh文件中,我想删除txt文件,我可以使用sh文件从终端删除,但我不能在web浏览器中执行

php文件

<?php 
if($_GET){
if(isset($_GET['test'])){
test();
}elseif(isset($_GET['delete'])){
delete();
}
}
function test()
{
$old_path = getcwd();
chdir('/var/www/html/admin');
$output= shell_exec("./test.sh");
chdir($old_path);
echo "<h1>$output</h1>";
}
function delete()
{
$old_path = getcwd();
chdir('/var/www/html/admin');
$output= shell_exec("./del.sh");
chdir($old_path);
echo "<h1>$output</h1>";
}
?>
<input type="submit" name="delete" class="btn btn-danger" value="delete">
<input type="submit" name= "test" class="btn btn-primary" value="test">

当我按下屏幕上打印的按钮但没有运行进程时,有sh文件要执行或删除文件

#!/bin/bash
echo 'delete file';
cd /var/www/html/test
rm text.txt 

尝试将您的输入放入表单中:

<form action="/"  method="get">
<input type="submit" name="delete" class="btn btn-danger" value="delete">
<input type="submit" name= "test" class="btn btn-primary" value="test">
</form>

您的php文件:

<?php
if($_GET){
if(isset($_GET['test'])){
test();
}elseif(isset($_GET['delete'])){
delete();
}
}
function test()
{
$old_path = getcwd();
chdir('/var/www/html/admin');
$output= shell_exec("./test.sh");
chdir($old_path);
echo "<h1>$output</h1>";
}
function delete()
{
$old_path = getcwd();
chdir('/var/www/html/admin');
$output= shell_exec("./del.sh");
chdir($old_path);
echo "<h1>$output</h1>";
}
?>
<form action="/"  method="get">
<input type="submit" name="delete" class="btn btn-danger" value="delete">
<input type="submit" name= "test" class="btn btn-primary" value="test">
</form>

最新更新