我有一个按钮可以创建一个文件夹,如果它没有被称为"创建文件夹"和一个删除文件夹的按钮,如果它存在,则调用"删除文件夹"。
如何设置按钮,以便在点击它们时执行它们的意图而不将按钮放在带有method = post的表单中?
因为我在点击按钮时使用$ _POST [' deleteFo']来接听。
<?php
$dir = scandir("uploads/admin@admin.com");
foreach($dir as $rows){
if ($rows == "." || $rows == ".."){
} else {
if(is_dir("uploads/admin@admin.com/".$rows)){
echo "Folder: $rows <br>";
} else {
echo "File: $rows <br>";
}
}
}
?>
<form method="post">
<input type="submit" name="createFo" value="Create Folder" id="CreateFolderBtn"/>
<?php
if (isset($_POST['createFo'])){
if (is_dir('uploads/admin@admin.com/examples')) {
echo "Examples Already Exists!";
} else {
mkdir('uploads/admin@admin.com/examples');
header('Refresh: 0');
}
echo "Examples Created!";
} else {echo "nop1";}
?>
<input type="submit" name="deleteFo" value="Delete Folder" id="DeleteFolderBtn"/>
<?php
if (isset($_POST['deleteFo'])){
if(!is_dir('uploads/admin@admin.com/examples')){
echo "Examples Forder doesn't exist!";
} else {
rmdir('uploads/admin@admin.com/examples');
header('Refresh: 0');
}
echo "Examples Folder Deleted!";
} else {echo "nop2";}
?>
</form>
输出:
Folder: New_Folder
File: Thumbs.db
File: Untitled.wma
Folder: pics
File: screenshot (4).png
File: screenshot.png
File: screenshot_(2).png
File: screenshot_(3).png
//button -> [Create Folder] nop1 //button -> [Delete Folder] nop2