<?php
// 网站url
$www = 'http://127.0.0.1';
// 主目录
$root = 'E:';
// GET目录信息
if (!empty($_GET['dir'])) {
$dir = $_GET['dir'] == 'undefined' ? $root . DIRECTORY_SEPARATOR : $_GET['dir'] . DIRECTORY_SEPARATOR;
// 是否在当前主目录下且是否为目录
// if (strpos($dir, $root) == 0 && is_dir(iconv('UTF-8', 'gbk', $dir))) { 解决编码问题
if (strpos($dir, $root) == 0 && is_dir($dir)) {
// 遍历当前目录下的文件和文件夹并存入filepaths中以json格式返回
$filepaths = ['paths' => [], 'files' => []];
// foreach (scandir(iconv('UTF-8', 'gbk', $dir)) as $filepath) { 解决编码问题
foreach (scandir($dir) as $filepath) {
if ($filepath == '.' || $filepath == '..') continue;
if (is_dir($dir . $filepath)) {
// $filepaths['paths'][] = $dir . iconv('gbk', 'utf-8', $filepath); 解决编码问题
$filepaths['paths'][] = $dir . $filepath;
} else {
// $filepaths['files'][] = $dir . iconv('gbk', 'utf-8', $filepath); 解决编码问题
$filepaths['files'][] = $dir . $filepath;
}
}
exit(json_encode($filepaths));
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>文件浏览器</title>
<link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/5.10.2/css/all.min.css">
<link rel="stylesheet" href="https://cdn.bootcss.com/dplayer/1.25.0/DPlayer.min.css">
<style>
* { margin: 0; padding: 0; font-family: "microsoft yahei"; }
.header { width: 100%; height: 60px; background-color: #333; line-height: 60px; color: #FFF; font-size: 30px; font-weight: 300; text-indent: 2%; }
.bar { padding: 0 2%; width: 96%; height: 40px; background-color: #EEE; border-top: 1px solid #DDD; border-bottom: 1px solid #DDD; overflow: hidden; zoom: 1; }
.bar .up { float: left; margin-top: 10px; height: 20px; line-height: 20px; color: #666; font-size: 16px; cursor: pointer; }
.bar .dir { float: left; margin: 10px 0 0 20px; height: 20px; line-height: 20px; color: #666; font-size: 16px; }
.content { padding: 10px 2%; width: 96%; }
.content dl { width: 100%; height: 40px; border-bottom: 1px dotted #CCC; overflow: hidden; zoom: 1; cursor: pointer; }
.content dl:hover { background-color: #F6F6F6; }
.content dl dt { float: left; margin-left: 10px; width: 40px; height: 40px; line-height: 40px; text-align: center; color: #666; font-size: 30px; }
.content dl dd { float: left; margin-left: 5px; line-height: 40px; text-align: center; }
#dplayer {display: none; width: 720px; height: 576px;}
</style>
</head>
<body>
<div class="header">文件浏览器</div>
<div class="bar">
<div class="up"><i class="fa fa-reply" aria-hidden="true"></i> 上级目录</div>
<div class="dir"></div>
</div>
<div class="content"></div>
<div id="dplayer"></div>
</body>
</html>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/layer/2.3/layer.js"></script>
<script src="https://cdn.bootcss.com/dplayer/1.25.0/DPlayer.min.js"></script>
<script src="https://cdn.bootcss.com/flv.js/1.5.0/flv.min.js"></script>
<script>
var root = '<?php echo str_replace("\\", "\\\\", $root); ?>';
const dp = new DPlayer({ container: document.getElementById('dplayer') });
function getDir(_dir) {
// 路径显示,不显示根目录
var path = _dir == undefined ? '\\' : _dir.replace(root, '') + '\\';
$('.dir').empty().append(path);
// 获取当前目录文件
$.getJSON('?dir=' + _dir, function(json) {
var list = '', i;
for (i in json.paths) {
list += '<dl data-path="' + json.paths[i] + '"><dt class="fa fa-folder" aria-hidden="true"></dt><dd>' + json.paths[i].replace(root + path, '') + '</dd></dl>';
}
for (i in json.files) {
list += '<dl data-file="' + json.files[i] + '"><dt class="fa fa-file" aria-hidden="true"></dt><dd>' + json.files[i].replace(root + path, '') + '</dd></dl>';
}
$('.content').empty().append(list);
});
}
$(function() {
getDir();
// 上一级目录
$('.up').on('click', function(){
var dir = $('.dir').text();
var dirCell = dir.split('\\');
if (dir != '\\' && dirCell.length > 2) {
getDir(root + dir.replace('\\' + dirCell[dirCell.length - 2] + '\\', ''));
}
});
$('.content').on('click', 'dl', function(){
var path = $(this).data('path'), file = $(this).data('file');
// 进入下一级目录
if (path) {
getDir(path);
}
// 播放flv文件
if (file && file.split('.').pop().toLowerCase() == 'flv') {
layer.open({
type: 1,
title: false,
area: ['720px', '576px'],
content: $('#dplayer'),
cancel: function(index, layero) {
dp.pause();
}
});
dp.switchVideo({ url: file.replace(root, '<?php echo $www ?>').replace(/\\/g, '/'), type: 'flv' });
dp.play();
}
});
});
</script>
php文件浏览,定制flv播放
最新推荐文章于 2021-04-13 04:53:31 发布