php ディレクトリ内のファイルを表示して再生

Pocket

[root@n54l flowplayer]# cat index.php 
<?php
$imagedir = opendir("./tv");
while (false !== ($file[] = readdir($imagedir)));
closedir($imagedir);
natsort($file);
reset($file);
$reverse = array_reverse($file, true);
    print "<TABLE border='1'>\n";
    print "<TR>\n";
    print "<TH>\</TH>\n";
    print "<TH>タイトル</TH>\n";
    print "</TR>\n";
while (false !== ($mp4 = each($reverse))){
  if (preg_match ("|.mp4$|", $mp4[1])) {
    print "<TR>\n";
    print "<TD>\n";
    print "<form method='POST' action='./video_view.php'>\n";
    print "<input type='hidden' name='video_data' value=" . $mp4[1] . ">\n";
    print "<input type='submit' name='btn1' value='視聴'>\n";
    print "</form>\n";
    print "</TD>\n";

    print "<td>" .  $mp4[1] . "</td>\n";
    print "</TR>\n";
  }
}
    print "</TABLE>\n";
?>
[root@n54l flowplayer]# 
[root@n54l flowplayer]# cat video_view.php 
<html>
<head>

   <link rel="stylesheet" href="skin/functional.css">

   <style>
   body { font: 12px "Myriad Pro", "Lucida Grande", sans-serif; text-align: center; padding-top: 5%; }
   .flowplayer { width: 80%; }
   </style>

   <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>

   <script src="flowplayer.min.js"></script>

</head>

<body>


<?php
$date = date("Ym");


$input_data = $_POST['video_data'];


print<<<EOF
   $input_data
   <div class="flowplayer" data-swf="flowplayer.swf" data-ratio="0.4167">
      <video>
        <source type="video/mp4" src="./tv/$input_data">;
      </video>
EOF;
?>
   </div>

</body>
</html>

ファイル表示を制限

[root@n54l flowplayer]# cat hukusuu.php 
<?php
if (isset($_GET["imageno"])) {
$imageno = $_GET["imageno"];
$image = $imageno;
}
$imagedir = opendir("./tv");
while (false !== ($file[] = readdir($imagedir)));
closedir($imagedir);
natsort($file);
reset($file);
$reverse = array_reverse($file, true);
if (!isset($imageno)) {
$imageno = 0;
$image = 0;
}
$pageline = 100;
$imagecount = 0;
    print "<TABLE border='1'>\n";
    print "<TR>\n";
    print "<TH>\</TH>\n";
    print "<TH>タイトル</TH>\n";
    print "</TR>\n";
while (false !== ($mp4 = each($reverse))){
if (preg_match ("|.mp4$|", $mp4[1])) {
$imagecount++;
if ($imageno == ($image+$pageline)) {
break;
}
if ($imagecount > $image) {
print "<TR>\n";
print "<TD>\n";
print "<form method='POST' action='./video_view.php'>\n";
print "<input type='hidden' name='video_data' value=" . $mp4[1] . ">\n";
print "<input type='submit' name='btn1' value='視聴'>\n";
print "</form>\n";
print "</TD>\n";
print "<td>" .  $mp4[1] . "</td>\n";
print "</TR>\n";

$imageno++;
}
}
}
print "</TABLE>\n";
?>
</div>
<div style="margin-top:12px;clear:both;">
<p class="txt">
<?php
$page = $imageno+$pageline;
if ($imageno > $pageline) {
$backno = $imageno-($pageline*2);
print "<a href='hukusuu.php?imageno=" . $backno . "'>back</a> ";
}
if ($imageno < $imagecount) {
print "<a href='hukusuu.php?imageno=" . $imageno . "'>next</a>";
}
?>

コメントを残す

メールアドレスが公開されることはありません。