mirror of
https://github.com/michalcz10/USB-RAID-Array.git
synced 2026-11-11 07:59:04 +00:00
48 lines
1.4 KiB
PHP
48 lines
1.4 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'] === 'createFile') {
|
|
$currentPath = requireRemotePath($_POST['currentPath'] ?? $defaultPath, $defaultPath);
|
|
|
|
if (!isset($_POST['fileName'])) {
|
|
http_response_code(400);
|
|
echo "File name is required";
|
|
exit;
|
|
}
|
|
|
|
$fileName = $_POST['fileName'];
|
|
|
|
if (strpos($fileName, '.') === false) {
|
|
http_response_code(400);
|
|
echo "File name must include an extension (e.g., .txt, .html, .php)";
|
|
exit;
|
|
}
|
|
|
|
$fileName = preg_replace('/[^\w\-\.]/', '_', $fileName);
|
|
|
|
if (!isRemoteNameValid($fileName)) {
|
|
http_response_code(400);
|
|
exit('Invalid file name.');
|
|
}
|
|
|
|
$newFilePath = rtrim($currentPath, '/') . '/' . $fileName;
|
|
header('Content-Type: application/json; charset=UTF-8');
|
|
if ($sftp->put($newFilePath, '')) {
|
|
echo json_encode(['success' => true, 'filePath' => $newFilePath]);
|
|
} else {
|
|
http_response_code(500);
|
|
echo json_encode(['success' => false, 'message' => 'Failed to create file.']);
|
|
}
|
|
exit;
|
|
}
|
|
|
|
http_response_code(400);
|
|
echo "Invalid request";
|
|
exit;
|