Created a file viewer and integrated it into the website.
This commit is contained in:
parent
5aebdbf605
commit
1fa0d503a0
3 changed files with 96 additions and 0 deletions
50
file_viewer.php
Normal file
50
file_viewer.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
function completeScanDir($dir) {
|
||||
$result = [];
|
||||
foreach(scandir($dir) as $filename) {
|
||||
if ($filename[0] === '.') continue;
|
||||
$filePath = $dir . '/' . $filename;
|
||||
|
||||
if (is_dir($filePath)) {
|
||||
$result[$filePath] = completeScanDir($filePath);
|
||||
|
||||
} else {
|
||||
$result[$filePath] = $filename;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function generateCSSCode($directory) {
|
||||
foreach ($directory as $path => $filename) {
|
||||
if (is_array($filename)) { // $filename is either a filename or an array of filenames, if so, it represents a directory
|
||||
$useableName = str_replace("/", "_", $path);
|
||||
echo "#input_$useableName:checked + .submenu_$useableName,
|
||||
.submenu_$useableName:hover {
|
||||
display: block;
|
||||
}\n";
|
||||
|
||||
generateCSSCode($filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function generateSubmenusHTML($directory, $indentation) {
|
||||
foreach ($directory as $path => $filename) {
|
||||
$useableName = str_replace("/", "_", $path); // CSS classes cant contain slashes
|
||||
|
||||
if (is_array($filename)) {
|
||||
$folderName = end(explode("/", $path));
|
||||
echo " $indentation<label for='input_$useableName' class='inset hcb-label label_$useableName'>$folderName</label>
|
||||
$indentation<input type='checkbox' id='input_$useableName' class='hacked-checkbox'>
|
||||
$indentation<div class='glass inset submenu submenu_$useableName'>\n";
|
||||
generateSubmenusHTML($filename, "$indentation ");
|
||||
echo " $indentation</div>
|
||||
$indentation<br>\n";
|
||||
} else {
|
||||
echo " $indentation<a href='$path' class='file-link'>$filename</a>\n";
|
||||
}
|
||||
echo " $indentation<br>\n";
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue