C:\xampp\htdocs\kptv\browser\browse.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
// Normalizează separatorul de directoare la slash universal (Linux-style)
function normalizePath($path) {
    return 
str_replace('\\''/'$path);
}

// Baza pentru navigare
$baseDir realpath(__DIR__ '/../images');
$baseDir normalizePath($baseDir);
$baseUrl '/images';

// Folder curent selectat din query
$subfolder = isset($_GET['folder']) ? $_GET['folder'] : '';
$subfolder str_replace('+'' '$subfolder);
$targetPath $baseDir . ($subfolder '/' $subfolder '');
$currentDir realpath($targetPath);

// Securitate: validare path și normalize
if (!$currentDir || strpos(normalizePath($currentDir), $baseDir) !== 0) {
    die(
'Access denied');
}

// Citim conținutul directorului
$items scandir($currentDir);
$folders = [];
$files = [];

foreach (
$items as $item) {
    if (
$item === '.' || $item === '..') continue;
    
$itemPath $currentDir '/' $item;
    if (
is_dir($itemPath)) {
        
$folders[] = $item;
    } else {
        
$files[] = $item;
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Select a file</title>
    <style>
        body { font-family: Arial, sans-serif; padding: 20px; background-color: #fff; }
        h2 { margin-bottom: 20px; }
        .file-grid { display: flex; flex-wrap: wrap; gap: 15px; }
        .file-item {
            width: 140px;
            text-align: center;
            cursor: pointer;
            border: 1px solid #ccc;
            padding: 10px;
            border-radius: 6px;
            background-color: #f9f9f9;
            transition: box-shadow 0.2s ease;
        }
        .file-item:hover { box-shadow: 0 0 10px rgba(0,0,0,0.2); }
        .file-item img {
            max-width: 100%;
            max-height: 100px;
            margin-bottom: 8px;
            object-fit: contain;
            border-radius: 4px;
        }
        .file-name { font-size: 14px; word-break: break-word; }
        .folder-item {
            font-weight: bold;
            background-color: #eef;
            color: #003366;
        }
        a.back-link {
            display: inline-block;
            margin-bottom: 20px;
            text-decoration: none;
            font-size: 16px;
            color: #000;
        }
    </style>
</head>
<body>
    <h2>Select a file</h2>

    <?php if ($subfolder): ?>
        <?php
        $parent 
dirname($subfolder);
        
$backLink = ($parent !== '.' && $parent !== '/') ? $parent '';
        
?>
        <a class="back-link" href="?folder=<?php echo urlencode($backLink); ?>">Back</a>
    <?php endif; ?>

    <div class="file-grid">
        <!-- Folders first -->
        <?php foreach ($folders as $folder): ?>
            <?php
            $folderPath 
= ($subfolder $subfolder '/' '') . $folder;
            
?>
            <div class="file-item folder-item" onclick="navigateTo('<?php echo urlencode($folderPath); ?>')">
                <div class="file-name"><?php echo htmlspecialchars($folder); ?></div>
            </div>
        <?php endforeach; ?>

        <!-- Files -->
        <?php foreach ($files as $file): ?>
            <?php
            $fileExt 
strtolower(pathinfo($filePATHINFO_EXTENSION));
            
$isImage in_array($fileExt, ['jpg''jpeg''png''gif''webp''svg']);
            
$itemRelPath = ($subfolder $subfolder '/' '') . $file;

            
// Corect URL encoding pentru fiecare parte
            
$parts explode('/'$itemRelPath);
            
$encodedParts array_map('rawurlencode'$parts);
            
$fileUrl $baseUrl '/' implode('/'$encodedParts);
            
?>
            <div class="file-item" onclick="selectFile('<?php echo $fileUrl?>')">
                <?php if ($isImage): ?>
                    <img src="<?php echo $fileUrl?>" alt="<?php echo htmlspecialchars($file); ?>" loading="lazy">
                <?php else: ?>
                    <img src="https://via.placeholder.com/100x100?text=FILE" alt="File" loading="lazy">
                <?php endif; ?>
                <div class="file-name"><?php echo htmlspecialchars($file); ?></div>
            </div>
        <?php endforeach; ?>
    </div>

    <script>
        function selectFile(url) {
            window.opener.CKEDITOR.tools.callFunction(
                <?php echo isset($_GET['CKEditorFuncNum']) ? intval($_GET['CKEditorFuncNum']) : 0?>,
                url
            );
            window.close();
        }

        function navigateTo(folder) {
            window.location.href = '?folder=' + encodeURIComponent(folder);
        }
    </script>
</body>
</html>
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586