commit 4a9d23669885e8d0531f09917f46d98dcc376685 Author: Strangedusk Date: Thu Jan 27 00:25:24 2022 +0100 Initial diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..6ecf20b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +content/* +favicon.* diff --git a/README.md b/README.md new file mode 100755 index 0000000..27a5132 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# NeoKino-PHP +## What is this +PHP script that allows the navigation of folders and shows files within the "./content" folder. +It is styled with a custom css that you may edit. It is also in catalan, which you may also change. diff --git a/index.php b/index.php new file mode 100755 index 0000000..d83d7d1 --- /dev/null +++ b/index.php @@ -0,0 +1,86 @@ + + + + + + Dusk Kino + + + + +File not found, error 404'; + +$basedir = 'content'; +$request_uri = $_SERVER['REQUEST_URI']; + +$path = $basedir . $request_uri; +$files_in_folder = scandir($path); + +// Debug +//var_dump($files_in_folder); +// Debug + +function link_from_file(string $filename, string $name = null, string $css_class = null ) : string { + // Check if css_class is null + $css_class = $css_class ? "class=\"$css_class\"" : ''; + // Check if name is null + $name = $name ?: basename($filename); + return sprintf('%s', $filename, $css_class, $name); +} + +function filter_files_dir($files_array, string $path) : array { + $ret_array = ['dir' => [], 'file' => []]; + foreach($files_array as $file) { + if(is_dir($path . $file)) { + // Append dir to array + $ret_array['dir'][] = $file; + } + else { + // Append file to array + $ret_array['file'][] = $file; + } + } + return $ret_array; +} + +if(!$files_in_folder) { + echo($not_found_error); + die(); +} + +$resource_array = filter_files_dir($files_in_folder, $path); + +// Show folder links +{ + foreach($resource_array['dir'] as $dir) { + if(substr($dir, 0, 1) == '.') { + continue; + } + echo(link_from_file($request_uri . $dir)); + echo('
'); + } + echo('
'); +} + +//Show file links +{ + foreach($resource_array['file'] as $file) { + if(substr($file, 0, 1) == '.') { + continue; + } + echo(link_from_file($request_uri . $file)); + echo('
'); + } + echo('
'); +} + +?> + + +