Moritz Schmidt 10 lat temu
rodzic
commit
5ad2ffa930
2 zmienionych plików z 43 dodań i 5 usunięć
  1. 27 5
      index.php
  2. 16 0
      readfile.php

+ 27 - 5
index.php

@@ -2,16 +2,38 @@
 
 $CONFIG = array(
     "paths" => array(
-        //"/media/Serien",
+        "/media/Serien",
         "/media/Filme"
     )
 );
 
-foreach($CONFIG['paths'] as $path) {
-    $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
-    foreach($objects as $name => $object){
-        echo "$name\n";
+if(!isset($_GET['path']) || !$_GET['path']) {
+    foreach($CONFIG['paths'] as $path) {
+        echo "<h2>" . $path . "</h2>";
+
+        $list = scandir($path);
+        $list = array_diff($list, array('.'));
+
+        foreach($list as $object) {
+            echo "<a href=\"?path=" . $path . "/" . $object . "\">" . $object . "</a><br>";
+        }
+    }
+} else {
+    echo "<h2>" . $_GET['path'] . "</h2>";
+    if(is_dir($_GET['path'])) {
+        $list = scandir($_GET['path']);
+        $list = array_diff($list, array('.'));
+        foreach($list as $object) {
+            echo "<a href=\"?path=" . $_GET['path'] . "/" .  $object . "\">" . $object . "</a><br>";
+        }
+    } else {
+        echo "<video width=\"auto\" height=\"auto\" controls>";
+        echo "<source src=\"readfile.php?file=" . $_GET['path'] . "\" type=\"video/mp4\">";
+        echo "Your browser does not support the video tag.";
+        echo "</video>";
     }
 }
 
+
+
 ?>

+ 16 - 0
readfile.php

@@ -0,0 +1,16 @@
+<?php
+
+if(!isset($_GET['file']) || !$_GET['file']) {
+    die();
+}
+
+header('Content-Type: video/mp4');
+
+$handle = fopen($_GET['file'], "r");
+$filesize = filesize($_GET['file']);
+$fs = 2097152; // 2mb
+while($fs < $filesize) {
+    echo fread($handle, $fs);
+    $fs += 2097152; // 2mb per cycle
+}
+fclose($handle);