mirror of
https://github.com/michalcz10/USB-RAID-Array.git
synced 2025-12-10 03:22:19 +00:00
WebApp production ver
This commit is contained in:
39
Web/betatest/content/ftp/delete.php
Normal file
39
Web/betatest/content/ftp/delete.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
require 'config.php';
|
||||
|
||||
$sftp = initializeSFTP($host, $username, $password);
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete'])) {
|
||||
$itemToDelete = $_POST['delete'];
|
||||
$parentDir = dirname($itemToDelete);
|
||||
|
||||
if ($parentDir === '/' || $parentDir === '.') {
|
||||
$parentDir = $defaultPath;
|
||||
}
|
||||
|
||||
if ($sftp->is_dir($itemToDelete)) {
|
||||
function deleteFolder($sftp, $folderPath) {
|
||||
$items = $sftp->nlist($folderPath);
|
||||
foreach ($items as $item) {
|
||||
if ($item === '.' || $item === '..') continue;
|
||||
$itemPath = $folderPath . '/' . $item;
|
||||
if ($sftp->is_dir($itemPath)) {
|
||||
deleteFolder($sftp, $itemPath);
|
||||
} else {
|
||||
$sftp->delete($itemPath);
|
||||
}
|
||||
}
|
||||
return $sftp->rmdir($folderPath);
|
||||
}
|
||||
|
||||
$success = deleteFolder($sftp, $itemToDelete);
|
||||
} else {
|
||||
$success = $sftp->delete($itemToDelete);
|
||||
}
|
||||
|
||||
header("Location: index.php?path=" . urlencode($parentDir));
|
||||
exit;
|
||||
}
|
||||
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
Reference in New Issue
Block a user