php文件浏览,定制flv播放

<?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>&nbsp;&nbsp;上级目录</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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值