php查找本地视频并可以在浏览器上播放(源码)

2017-11-16  本文已影响26人  LauEl
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>视频查找</title>
</head>
<body>

<form action="index.php" method="post">
    <input type="text" name="name" placeholder="请输入文件夹名">
    <input type="submit">
</form>
</body>
</html>
<?php
header("content-type:text/html;charset=utf-8");
function read_all_dir($dir) {
    if (!is_dir($dir)) {
        echo "<script>alert('未找到该文件夹,请重新输入!')</script>";
        die;
    }
    $result = array();
    @$handle = opendir($dir);
    if ($handle) {
        while (($file = readdir($handle)) !== false) {
            if ($file != '.' && $file != '..') {
                $cur_path = $dir . DIRECTORY_SEPARATOR . $file;
                if (is_dir($cur_path)) {
                    $result['dir'][$cur_path] = read_all_dir($cur_path);
                } else {
                    $result['file'][] = $cur_path;
                    $result['files'][] = $file;
                }
            }
        }
        closedir($handle);
    }
    return $result;
}

//$all = read_all_dir("D:\\wamp\\www\\123");
//$dirname = "20170405";
@$name = $_POST['name'];
$dirname = $name;
$all = read_all_dir("/Applications/XAMPP/xamppfiles/htdocs/lianxi/" . $dirname);
@$files = $all['files'];
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>播放本地视频</title>
    <!--    <script src="jquery-1.8.3.min.js"></script>-->
    <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
    <script>
        $(function () {
            //以下是调用浏览器判断的函数
            var mb = myBrowser();
            if ("IE" == mb) {
                //alert("我是 IE");
            }
            if ("FF" == mb) {
                //alert("我是 Firefox");
            }
//            if ("Chrome" == mb) {
//                alert("该浏览器播放视频时会出现异常,请切换到其他浏览器!");
//            }
            /*if ("Opera" == mb) {
             alert("我是 Opera");
             }
             if ("Safari" == mb) {
             alert("我是 Safari");
             }*/
            $('ol li').click(function () {
                var fname = $(this).html();
                $(this).css("color", "blue").siblings().css("color", "black");
//                $('video').attr("src", "http://localhost/123/" + fname);
                $('video').attr("src", "http://localhost/lianxi/" + <?php echo "$dirname"?>+"/" + fname);
            });
        });
        function myBrowser() {
            var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
            var isOpera = userAgent.indexOf("Opera") > -1;
            if (isOpera) {
                return "Opera"
            }
            ; //判断是否Opera浏览器
            if (userAgent.indexOf("Firefox") > -1) {
                return "FF";
            } //判断是否Firefox浏览器
            if (userAgent.indexOf("Chrome") > -1) {
                return "Chrome";
            }
            if (userAgent.indexOf("Safari") > -1) {
                return "Safari";
            } //判断是否Safari浏览器
            if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
                return "IE";
            }
            ; //判断是否IE浏览器
        }
    </script>
</head>
<body>
<!--http://localhost/123/123.MP4-->
<!--width="480" height="420"-->
<p>视频文件目录放在设置的目录下</p>
<div style="width:200px;float:left;border:1px solid gray;min-height:200px;margin-right:20px;">
    <h4 style="text-align:center;">文件列表</h4>
    <ol>
        <?php foreach ($files as $v) { ?>
            <li style="cursor:pointer;"><?php echo $v; ?></li>
        <?php } ?>
    </ol>
</div>
<div style="float:left;border:0px solid gray;width:500px;height:290px;">
    <!--    <embed src="http://localhost/123/111.jpg" quality="high" width="100%" height="100%"-->
    <!--           align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" autostart="true" >-->
    <!--    </embed>-->
    <video src="http://localhost/123/1234.MP4" controls="controls" width="100%" height="100%">
        your browser does not support the video tag
    </video>
</div>
<div style="clear:both;"></div>

</body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读