optimize the code in terminal.php;

This commit is contained in:
2024-07-15 09:38:43 +08:00
parent 0279ae6493
commit 36a7eecf94
7 changed files with 63 additions and 25 deletions
+2 -3
View File
@@ -1,8 +1,8 @@
<?php
function cd($commands)
{
if(sizeof($commands)>2){
file_put_contents("recent.txt", "Too many arguments.<br/>", FILE_APPEND);
if (sizeof($commands) > 2) {
file_put_contents("recent.txt", "Invalid number of arguments.<br/>", FILE_APPEND);
return;
}
$pwd = file_get_contents("pwd.txt");
@@ -23,4 +23,3 @@ function cd($commands)
}
}
}
?>
+9
View File
@@ -0,0 +1,9 @@
<?php
function clear($commands)
{
if (sizeof($commands) == 1) {
file_put_contents("recent.txt", "");
} else {
file_put_contents("recent.txt", "Invalid number of arguments.<br/>", FILE_APPEND);
}
}
+12
View File
@@ -0,0 +1,12 @@
<?php
function help($commands)
{
$help = file_get_contents("static/terminal.php/help.txt");
if (sizeof($commands) == 1) {
file_put_contents("recent.txt", $help, FILE_APPEND);
} else if (sizeof($commands) == 2 && file_get_contents("static/help/$commands[1].txt") != NULL) {
file_put_contents("recent.txt", file_get_contents("static/help/$commands[1].txt"), FILE_APPEND);
} else {
file_put_contents("recent.txt", "Invalid number of arguments.<br/>", FILE_APPEND);
}
}
+16
View File
@@ -0,0 +1,16 @@
<?php
function mdir($commands)
{
$pwd = file_get_contents("pwd.txt");
if (sizeof($commands) == 2) {
if (!opendir("fileroot" . $pwd . "/" . $commands[1])) {
if (!mkdir("fileroot" . $pwd . "/" . $commands[1])) {
file_put_contents("recent.txt", "Error creating directory.No permissions?<br/>", FILE_APPEND);
}
} else {
file_put_contents("recent.txt", "Directory already exists.<br/>", FILE_APPEND);
}
} else {
file_put_contents("recent.txt", "Invalid number of arguments.<br/>", FILE_APPEND);
}
}
+10
View File
@@ -0,0 +1,10 @@
<?php
function pwd($commands)
{
$pwd = file_get_contents("pwd.txt");
if (sizeof($commands) == 1) {
file_put_contents("recent.txt", $pwd . "<br/>", FILE_APPEND);
} else {
file_put_contents("recent.txt", "Invalid number of arguments.<br/>", FILE_APPEND);
}
}
+3 -2
View File
@@ -20,7 +20,7 @@ function rm($commands)
} else {
file_put_contents("recent.txt", "Not a directory.<br/>", FILE_APPEND);
}
} else {
} else if (sizeof($commands) == 2) {
if (is_dir("fileroot" . $pwd . "/" . $commands[1])) {
file_put_contents("recent.txt", "Is a directory.<br/>Try rm -r<br/>", FILE_APPEND);
} else {
@@ -30,6 +30,7 @@ function rm($commands)
file_put_contents("recent.txt", "Error deleting.<br/>", FILE_APPEND);
}
}
} else {
file_put_contents("recent.txt", "Invalid number of arguments.<br/>", FILE_APPEND);
}
}
?>