mirror of
https://github.com/michalcz10/USB-RAID-Array.git
synced 2026-11-11 07:59:04 +00:00
42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../../includes/auth.php';
|
|
requireLogin('../../index.php');
|
|
requirePermission('upPer', 'You do not have permission to perform this operation.');
|
|
|
|
require_once __DIR__ . '/../../config/config.php';
|
|
|
|
$sftp = initializeSFTP();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'createDir') {
|
|
$currentPath = requireRemotePath($_POST['currentPath'] ?? $defaultPath, $defaultPath);
|
|
|
|
if (!isset($_POST['dirName'])) {
|
|
http_response_code(400);
|
|
echo "Directory name is required";
|
|
exit;
|
|
}
|
|
|
|
$directoryName = $_POST['dirName'];
|
|
|
|
$directoryName = preg_replace('/[^\w\-\.]/', '_', $directoryName);
|
|
|
|
if (!isRemoteNameValid($directoryName)) {
|
|
http_response_code(400);
|
|
exit('Invalid directory name.');
|
|
}
|
|
|
|
$newDirectoryPath = rtrim($currentPath, '/') . '/' . $directoryName;
|
|
|
|
if ($sftp->mkdir($newDirectoryPath)) {
|
|
echo "Directory created successfully!";
|
|
} else {
|
|
http_response_code(500);
|
|
echo "Failed to create directory.";
|
|
}
|
|
exit;
|
|
}
|
|
|
|
http_response_code(400);
|
|
echo "Invalid request";
|
|
exit;
|