这是本人原创的文件查看系统,咱废话不多说,直接上代码~
PHP代码:
<?php
//PHP代码:
error_reporting(0);
// 目录
function listDir($root){
$param = $_GET['dir'];
$url = explode('/', $param);
$now_dir = current(array_reverse($url));
if ($now_dir == '..') {
array_pop($url);
array_pop($url);
}
$new = implode('/', $url);
$_GET['dir'] = $new;
$direct = explode('/', $root);
$last = current(array_reverse($direct));
array_pop($direct);
$rootDir = implode('/', $direct);
$new_url = $rootDir.'/<a href="'.$_SERVER['PHP_SELF'].'">'.$last.'</a>';
foreach ($url as $k => $v) {
if (!empty($v)) {
$vv .= '/'.$v;
$new_url .= '/<a href="?dir='.$vv.'">'.$v.'</a>';
}
}
$res['root'] = $new_url;
if ($new) {
$root .= '/'.$new;
}
$dir = scandir($root,1);
foreach ($dir as $k => $v) {
$new = $root.'/'.$v;
if ($v == '..') {
$res[$v]['type'] = 1;
$res[$v]['size'] = 1;
}elseif (is_dir($new) && $v!='.') {
$res[$v]['type'] = 1;
$res[$v]['size'] = 0;
}elseif($v!='.'){
$res[$v]['type'] = 0;
$res[$v]['size'] = filesize($new);
}
}
$sort = array_values($res);
array_multisort($res,SORT_DESC,$sort);
return $res;
}
?>HTML代码:
<!-- HTML代码 -->
<?php $root = 'D:/phpStudy/www/laravel-master';$dir = listDir($root);?>
<p>当前目录:<?php echo $dir['root'];unset($dir['root']);?></p>
<table border="1" cellspacing="0" cellpadding="1" width="520">
<tr>
<th>类型</th>
<th>文件名</th>
<th>文件大小(kb)</th>
</tr>
<?php foreach ($dir as $k => $v): ?>
<tr>
<td class='type'><?php if($v['type'] ==1){echo '目录';}else{echo '文件';}?></td>
<td style="padding-left:7px;">
<?php
if($v['type'] ==1){
if($_GET['dir'] != '' || $k != '..'){
echo "<a href='?dir=".$_GET['dir'].'/'.$k."'>";
}
}?>
<?php echo $k;?>
<?php
if($v['type'] ==1){
if($_GET['dir'] != '' || $k != '..'){
echo '</a>';
}
}?>
</td>
<td class="action"><?php echo $k=='..'?'未知':($v['size']==0?'---':$v['size']);?></td>
</tr>
<?php endforeach ?>
</table>
<style>
.type{text-align: center;}
.action{text-align: center;}
a{text-decoration: none;color: blue;}
</style>最后出来的效果图如下:(注:蓝色字体部分是目录,可点击进入查看目录里的文件)

附上FileSystem的升级版:
FileSystem.zip
没有难的技术,当你弄清它的原理时,你会发现原来如此简单~ 欢迎加群【195474288】讨论
