mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 12:34:47 -04:00
Add folder deletion.
This commit is contained in:
parent
8fa939ae30
commit
62e60cffd3
3 changed files with 27 additions and 6 deletions
|
@ -89,7 +89,7 @@ Options
|
||||||
},
|
},
|
||||||
|
|
||||||
/* [EXPERIMENTAL]
|
/* [EXPERIMENTAL]
|
||||||
Allow file deletion.
|
Allow file and folder deletion. Be careful with this option!
|
||||||
*/
|
*/
|
||||||
"delete": {
|
"delete": {
|
||||||
"enabled": false
|
"enabled": false
|
||||||
|
|
|
@ -169,9 +169,9 @@ class Api {
|
||||||
|
|
||||||
if ($code == MAGIC_SEQUENCE && !$this->app->is_ignored($n)) {
|
if ($code == MAGIC_SEQUENCE && !$this->app->is_ignored($n)) {
|
||||||
|
|
||||||
$abs_path = $this->app->to_path($href);
|
$path = $this->app->to_path($href);
|
||||||
|
|
||||||
if (!unlink($abs_path)) {
|
if (!delete_path($path, true)) {
|
||||||
$errors[] = $href;
|
$errors[] = $href;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,10 +196,10 @@ class Api {
|
||||||
|
|
||||||
if ($code == MAGIC_SEQUENCE && !$this->app->is_ignored($n)) {
|
if ($code == MAGIC_SEQUENCE && !$this->app->is_ignored($n)) {
|
||||||
|
|
||||||
$abs_path = $this->app->to_path($href);
|
$path = $this->app->to_path($href);
|
||||||
$folder = normalize_path(dirname($abs_path));
|
$folder = normalize_path(dirname($path));
|
||||||
|
|
||||||
if (!rename($abs_path, $folder . "/" . $name)) {
|
if (!rename($path, $folder . "/" . $name)) {
|
||||||
json_fail(2, "renaming failed");
|
json_fail(2, "renaming failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,27 @@ function exec_cmdv($cmdv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function delete_path($path, $recursive = false) {
|
||||||
|
|
||||||
|
if (is_file($path)) {
|
||||||
|
return @unlink($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_dir($path)) {
|
||||||
|
if ($recursive === true && $dir = opendir($path)) {
|
||||||
|
while (($name = readdir($dir)) !== false) {
|
||||||
|
delete_path($path . "/" . $name);
|
||||||
|
}
|
||||||
|
closedir($dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return @rmdir($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// debug tools
|
// debug tools
|
||||||
|
|
||||||
function err_log($message, $obj = null) {
|
function err_log($message, $obj = null) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue