[英]deleting file using sh file in web with php
嗨,我有一個PHP文件,有2個按鈕來執行一個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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.