| Name |
Size |
Modified |
Actions |
";
// Go to parent folder
echo "
|
[ GO TO PARENT FOLDER ]
|
";
$items = array_diff(scandir($path), ['.', '..']);
foreach($items as $item) {
$full_path = $path . '/' . $item;
$is_folder = is_dir($full_path);
$icon = $is_folder ? '📁' : '📄';
$size = $is_folder ? '-' : format_size(filesize($full_path));
$date = date('d.m.Y H:i', filemtime($full_path));
echo "";
// Name
echo "| $icon ";
if($is_folder) {
echo "$item";
} else {
echo "$item";
}
echo " | ";
// Size
echo "$size | ";
// Date
echo "$date | ";
// Actions
echo "";
if(!$is_folder) {
echo "[Edit] ";
echo "[View] ";
}
echo "[Rename] ";
echo "[Delete]";
echo " | ";
echo "
";
}
echo "";
}
// Format size
function format_size($bytes) {
if($bytes < 1024) return $bytes . ' B';
if($bytes < 1048576) return round($bytes/1024, 2) . ' KB';
return round($bytes/1048576, 2) . ' MB';
}
// Upload file
function upload_file($target) {
global $allowed_extensions;
$file = $_FILES['upload_file'];
$extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
if(!in_array($extension, $allowed_extensions)) {
return "ERROR: .$extension extension not allowed";
}
if(move_uploaded_file($file['tmp_name'], $target . '/' . $file['name'])) {
return "OK: " . $file['name'] . " uploaded";
}
return "ERROR: Upload failed";
}
// Create folder
function create_folder($path) {
$name = trim($_POST['new_folder']);
if(empty($name)) return "ERROR: Folder name required";
$new_path = $path . '/' . $name;
if(mkdir($new_path)) {
return "OK: $name folder created";
}
return "ERROR: Folder creation failed";
}
// Create file
function create_file($path) {
$name = trim($_POST['new_file']);
$content = $_POST['file_content'] ?? '';
if(empty($name)) return "ERROR: File name required";
$new_path = $path . '/' . $name;
if(file_put_contents($new_path, $content) !== false) {
return "OK: $name file created";
}
return "ERROR: File creation failed";
}
// Edit file
function edit_file($path) {
if($_SERVER['REQUEST_METHOD'] == 'POST') {
file_put_contents($path, $_POST['content']);
echo "
File saved
";
}
$content = htmlspecialchars(file_get_contents($path));
$name = basename($path);
echo "Edit: $name
";
}
// View file
function view_file($path) {
$content = htmlspecialchars(file_get_contents($path));
$name = basename($path);
echo "View: $name
Go Back";
}
// Delete
function delete_item($path) {
if(is_dir($path)) {
rmdir($path);
return "OK: Folder deleted";
} else {
unlink($path);
return "OK: File deleted";
}
}
// Rename
function rename_item($path) {
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$new_name = trim($_POST['new_name']);
$new_path = dirname($path) . '/' . $new_name;
if(rename($path, $new_path)) {
echo "";
return;
}
}
$current_name = basename($path);
echo "Rename: $current_name
";
}
// ========================
// ACTION HANDLER
// ========================
$message = '';
$special_action = false;
// POST actions
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($_FILES['upload_file'])) {
$message = upload_file($current_folder);
}
elseif(isset($_POST['new_folder'])) {
$message = create_folder($current_folder);
}
elseif(isset($_POST['new_file'])) {
$message = create_file($current_folder);
}
}
// GET actions
$action = $_GET['action'] ?? '';
if($action && $file_name) {
$special_action = true;
switch($action) {
case 'edit':
edit_file($file_path);
break;
case 'view':
view_file($file_path);
break;
case 'delete':
$message = delete_item($file_path);
break;
case 'rename':
rename_item($file_path);
break;
}
}
// ========================
// INTERFACE
// ========================
?>
File Manager
📂 File Manager
Folder:
Total: items
PHP |
Memory: MB |
Server: