mirror of
https://github.com/michalcz10/USB-RAID-Array.git
synced 2026-11-11 07:59:04 +00:00
Use portable POSIX parent paths instead of platform-dependent dirname() for remote navigation, previews, uploads, file operations and shared URLs. Normalize browser paths, avoid doubled root separators and preserve top-level directory names in ZIP downloads. Add regression coverage for root navigation, generated links, relative paths and ZIP members, and document the new test command. Verified with PHP syntax checks and all three regression suites.
48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
if(!isset($_SESSION['uname'])){
|
|
header("location: ../../index.php");
|
|
session_destroy();
|
|
exit;
|
|
}
|
|
|
|
if(!isset($_SESSION["upPer"]) || $_SESSION["upPer"] != true) {
|
|
die("You don't have permission to rename files or directories.");
|
|
}
|
|
|
|
ini_set('display_errors', 1);
|
|
error_reporting(E_ALL);
|
|
|
|
require_once __DIR__ . '/../../config/config.php';
|
|
$sftp = initializeSFTP();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$oldPath = isset($_POST['path']) ? $_POST['path'] : '';
|
|
$newName = isset($_POST['newName']) ? trim($_POST['newName']) : '';
|
|
$isDirectory = isset($_POST['isDirectory']) && $_POST['isDirectory'] == '1';
|
|
|
|
if (empty($oldPath) || empty($newName)) {
|
|
die("Missing required information for renaming.");
|
|
}
|
|
|
|
$dirPath = remoteDirname($oldPath);
|
|
$oldName = basename($oldPath);
|
|
|
|
$newPath = $dirPath . '/' . $newName;
|
|
|
|
if ($sftp->file_exists($newPath) || $sftp->is_dir($newPath)) {
|
|
die("Error: A file or directory with this name already exists.");
|
|
}
|
|
|
|
if ($sftp->rename($oldPath, $newPath)) {
|
|
header("Location: index.php?path=" . urlencode($dirPath));
|
|
exit;
|
|
} else {
|
|
die("Failed to rename the item. Please try again.");
|
|
}
|
|
} else {
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
?>
|