diff --git a/api/copy.php b/api/copy.php new file mode 100644 index 0000000..0117b48 --- /dev/null +++ b/api/copy.php @@ -0,0 +1,37 @@ +false, 'error'=>'Invalid paths']); + exit; +} + +$basename = basename($srcReal); +$target = $destReal . '/' . $basename; + +if (is_dir($srcReal)) { + $rc = mkdir($target); + // simple recursive copy + $it = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($srcReal, FilesystemIterator::SKIP_DOTS), + RecursiveIteratorIterator::SELF_FIRST + ); + foreach ($it as $item) { + $subPath = $target . substr($item->getPathname(), strlen($srcReal)); + if ($item->isDir()) mkdir($subPath); + else copy($item->getPathname(), $subPath); + } + $ok = $rc; +} else { + $ok = copy($srcReal, $target); +} + +echo json_encode(['success'=>(bool)$ok]); diff --git a/api/delete.php b/api/delete.php new file mode 100644 index 0000000..9aa6cca --- /dev/null +++ b/api/delete.php @@ -0,0 +1,26 @@ +false,'error'=>'Not found']); + exit; +} + +function rrmdir($d) { + foreach (scandir($d) as $f) { + if (in_array($f, ['.','..'])) continue; + $p = "$d/$f"; + is_dir($p) ? rrmdir($p) : unlink($p); + } + rmdir($d); +} + +if (is_dir($real)) rrmdir($real); +else unlink($real); + +echo json_encode(['success'=>true]); diff --git a/api/info.php b/api/info.php new file mode 100644 index 0000000..c0bcad2 --- /dev/null +++ b/api/info.php @@ -0,0 +1,19 @@ + basename($real), + 'type' => is_dir($real) ? 'directory' : 'file', + 'size' => is_file($real) ? filesize($real) : null, + 'mtime' => date(DATE_ISO8601, filemtime($real)), + 'path' => virtualize_path($real), +]); diff --git a/api/list.php b/api/list.php new file mode 100644 index 0000000..a4856e0 --- /dev/null +++ b/api/list.php @@ -0,0 +1,30 @@ + $name, + 'virtual' => virtualize_path($full), + 'isDir' => is_dir($full), + 'ext' => pathinfo($name, PATHINFO_EXTENSION), + 'size' => is_file($full) ? filesize($full) : null, + 'mtime' => filemtime($full), + ]; +} + +echo json_encode($out); diff --git a/api/move.php b/api/move.php new file mode 100644 index 0000000..517cecb --- /dev/null +++ b/api/move.php @@ -0,0 +1,20 @@ +false,'error'=>'Invalid paths']); + exit; +} + +$target = $destReal . '/' . basename($srcReal); +$ok = rename($srcReal, $target); + +echo json_encode(['success'=>(bool)$ok]); diff --git a/api/rename.php b/api/rename.php new file mode 100644 index 0000000..dbab108 --- /dev/null +++ b/api/rename.php @@ -0,0 +1,18 @@ +false,'error'=>'Not found']); + exit; +} + +$ok = rename($oldReal, $newReal); +echo json_encode(['success'=>(bool)$ok]); diff --git a/api/search.php b/api/search.php new file mode 100644 index 0000000..629fdf5 --- /dev/null +++ b/api/search.php @@ -0,0 +1,36 @@ +getFilename(); + if (!$showHidden && strpos($name, '.') === 0) continue; + if (stripos($name, $q) === false) continue; + + $full = $f->getPathname(); + $out[] = [ + 'name' => $name, + 'virtual' => virtualize_path($full), + 'isDir' => $f->isDir(), + 'ext' => $f->getExtension(), + 'size' => $f->getSize(), + 'mtime' => $f->getMTime(), + ]; +} + +echo json_encode($out); diff --git a/delete.php b/delete.php index acda6f6..7e38544 100644 --- a/delete.php +++ b/delete.php @@ -1,38 +1,41 @@ false, 'error' => 'Invalid request method']); + exit; +} + $data = json_decode(file_get_contents('php://input'), true); -if (empty($data['path'])) { - echo json_encode(['success' => false, 'error' => 'Missing path']); +$path = $_SERVER['DOCUMENT_ROOT'] . '/' . $data['path']; + +if (!file_exists($path)) { + echo json_encode(['success' => false, 'error' => 'File/folder does not exist']); exit; } -// Resolve path properly -$delFullPath = realpath($rootDir . '/' . ltrim($data['path'], '/')); - -// Validate path -if (!$delFullPath || strpos($delFullPath, $rootDir) !== 0) { - echo json_encode(['success' => false, 'error' => 'Invalid path']); - exit; -} - -// Recursive deletion -function deleteRecursively($path) { - if (is_dir($path)) { - $items = scandir($path); - foreach ($items as $item) { - if ($item === '.' || $item === '..') continue; - deleteRecursively($path . DIRECTORY_SEPARATOR . $item); - } - return rmdir($path); - } elseif (is_file($path)) { - return unlink($path); - } - return false; -} - -if (deleteRecursively($delFullPath)) { - echo json_encode(['success' => true]); +// Check if it's a directory +if (is_dir($path)) { + // Delete recursively + deleteDirectory($path); } else { - echo json_encode(['success' => false, 'error' => 'Delete failed']); + unlink($path); } + +echo json_encode(['success' => true]); +?> + + diff --git a/explorer.html b/explorer.html new file mode 100644 index 0000000..97b39f3 --- /dev/null +++ b/explorer.html @@ -0,0 +1,281 @@ + + + +
+ +Current directory: