← BACK

File Explorer dot php.txt

<?php
$baseDir = realpath(__DIR__);

$dir = $_GET['dir'] ?? '';

$requestedDir = realpath($baseDir . DIRECTORY_SEPARATOR . $dir);

if (
    $requestedDir === false ||
    strpos($requestedDir, $baseDir) !== 0
) {
    $requestedDir = $baseDir;
}

$currentDir = $requestedDir;
$relativePath = trim(str_replace($_SERVER['DOCUMENT_ROOT'], '', $currentDir), '/');

// Ambil semua item mentah
$allItems = array_diff(scandir($currentDir), ['.', '..', basename(__FILE__)]);

$folders = [];
$files = [];

foreach ($allItems as $item) {
    $fullPath = $currentDir . DIRECTORY_SEPARATOR . $item;
    if (is_dir($fullPath)) {
        $folders[] = $item;
    } else {
        $files[] = $item;
    }
}

// Gabungkan: Folder duluan, baru File
$items = array_merge($folders, $files);

function formatSize($bytes)
{
    if ($bytes >= 1073741824) {
        return number_format($bytes / 1073741824, 2) . ' GB';
    } elseif ($bytes >= 1048576) {
        return number_format($bytes / 1048576, 2) . ' MB';
    } elseif ($bytes >= 1024) {
        return number_format($bytes / 1024, 2) . ' KB';
    } else {
        return $bytes . ' B';
    }
}

function badgeClass($ext)
{
    $map = [
        'pdf' => 'pdf',
        'zip' => 'zip',
        'rar' => 'zip',
        '7z'  => 'zip',
        'jpg' => 'image',
        'jpeg'=> 'image',
        'png' => 'image',
        'webp'=> 'image',
        'gif' => 'image',
        'doc' => 'doc',
        'docx'=> 'doc',
        'xls' => 'excel',
        'xlsx'=> 'excel',
        'sql' => 'sql',
        'txt' => 'txt'
    ];

    return $map[$ext] ?? 'default';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">


<title>File Explorer</title>

<style>
*{
    margin:0;
    padding:0;
    box-sizing:border-box;
    color: #ffffff;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
}

body{
    font-family:Segoe UI, sans-serif;
    background:
    linear-gradient(
    135deg,
    #0b1223,
    #111827,
    #233044);
    min-height:100vh;
    color:#fff;
    padding:10px 7px 10px 7px;
}

.container{
    max-width:1200px;
    margin:auto;
}

.header{
    margin-bottom:13px;
}

.title{
    font-size:23px;
    font-weight:700;
}

.breadcrumb{
    margin-top:6px;
    opacity:.7;
    font-size:15px;
    word-break:break-all;
}

.card{
    background:rgba(255,255,255,.05);
    border:1px solid rgba(255,255,255,.35);
    backdrop-filter:blur(12px);
    border-radius:6px;
    overflow:hidden;
}

.table-header,
.row{
    display:grid;
    grid-template-columns:
    1.5fr
    100px
    140px
    120px;
    gap:15px;
    align-items:center;
}

.table-header{
    padding:18px;
    border-bottom:1px solid rgba(255,255,255,.25);
    font-weight:600;
}

.row{
    padding:5px 8px 5px 8px;
    border-bottom:1px solid rgba(255,255,255,.25);
}

.row:last-child{
    border-bottom:none;
}

.file{
    display:flex;
    align-items:center;
    gap:12px;
}

.icon{
    font-size:24px;
}

.badge{
    display:inline-block;
    padding:4px 10px;
    border-radius:5px;
    font-size:10px;
    font-weight:600;
}

.pdf{
    background:#dc2626;
}

.zip{
    background:#f59e0b;
}

.image{
    background:#22c55e;
}

.doc{
    background:#2563eb;
}

.excel{
    background:#15803d;
}

.sql{
    background:#7c3aed;
}

.txt{
    background:#64748b;
}

.default{
    background:#475569;
}

.download-btn{
    display:inline-block;
    text-decoration:none;
    color:white;
    font-size: 12px;
    background: #1857de;
    padding:7px 13px;
    border-radius:6px;
    transition:.2s;
    text-align:center;
}

.download-btn:hover{
    transform:translateY(-2px);
}

.folder{
    color:#fbbf24;
}

@media(max-width:768px){

.table-header{
    display:none;
}

/*.row{
    display:flex;
    flex-direction:column;
    align-items:flex-start;
    gap:8px;
}*/

.row{
    display:grid;
    grid-template-columns:
        1fr
        auto
        auto
        auto;
    gap:8px;
    align-items:center;
}

.download-btn{
    width:100%;
}
}
</style>
</head>
<body>

<div class="container">

<div class="header">
<div class="title">File Explorer</div>

<div class="breadcrumb">

<a href="?">HOME</a>

<?php

$parts = array_filter(explode('/', $dir));

$current = '';

foreach($parts as $part)
{
    $current .= ($current ? '/' : '') . $part;

    echo ' / ';
    echo '<a href="?dir=' .
         urlencode($current) .
         '">' .
         htmlspecialchars($part) .
         '</a>';
}

?>

</div>
</div>

<div class="card">

<div class="table-header">
<div>Name</div>
<div>Type</div>
<div>Size</div>
<div>Action</div>
</div>
<?php

if(!empty($dir))
{
    $parent = dirname($dir);

    if($parent === '.')
    {
        $parent = '';
    }

    echo '
    <div class="row">
        <div class="file">
            ← Parent Directory
        </div>

        <div></div>
        <div></div>

        <div>
            <a class="download-btn"
               href="?dir=' .
               urlencode($parent) .
               '">
               Back
            </a>
        </div>
    </div>';
}

?>
<?php foreach($items as $item): ?>

<?php
$path = $currentDir . DIRECTORY_SEPARATOR . $item;

if(is_dir($path))
{
    $type = 'FOLDER';
    $badge = 'default';
    $size = '-';
}
else
{
    $ext = strtolower(pathinfo($item, PATHINFO_EXTENSION));
    $type = strtoupper($ext ?: 'FILE');
    $badge = badgeClass($ext);
    $size = formatSize(filesize($path));
}
?>

<div class="row">

<div class="file">

<?php if(is_dir($path)): ?>
<span class="icon">📁</span>
<?php endif; ?>

<span>
<?php echo htmlspecialchars($item); ?>
</span>

</div>

<div>
<?php if(!is_dir($path)): ?>
<span class="badge <?php echo $badge; ?>">
    <?php echo $type; ?>
</span>
<?php endif; ?>
</div>

<div>
<?php echo $size; ?>
</div>

<div>

<?php if(is_dir($path)): ?>

<a class="download-btn"
href="?dir=<?php
echo urlencode(
trim($dir . '/' . $item, '/')
);
?>">
Open

</a>

<?php else: ?>

<a class="download-btn"
href="<?php echo rawurlencode($item); ?>"
download>

Download

</a>

<?php endif; ?>

</div>

</div>

<?php endforeach; ?>

</div>

</div>

</body>
</html>