php2-3v690,php网页版文件浏览器
发布日期:2021-06-27 04:24:27 浏览次数:12 分类:技术文章

本文共 9209 字,大约阅读时间需要 30 分钟。

/*〈view 部分〉*/

?>

php网页版文件浏览器

.filesize{float: right; color: #89a}

〈controller 部分〉

本程序的关键函数是 glob() 请查阅 php 手册*/

classManager{private $dirDataStructure;private $dirArr;private $icon;public function__construct(){if(isset($_SESSION["dir"])){$this->dirDataStructure = $_SESSION["dir"];

}else{$this->dirDataStructure = explode('/',__DIR__);

}//设置图标尺寸

$w = 24;$h = 24;//图标组

$this->icon = array('dir' => '

'/path>

',

'picture' => ''.

'path>'.

'

'fill="#25AE88" p-id="42224">

',

'video' => ''.

'',

'music' => '

' fill="#2D8CF0" p-id="10755">

'l="#97C6FF" p-id="10756">

',

'text' => '

'-id="2002">

'>

',

'configuration' => '',

'html' => ''.

'

'l="#F75B60" p-id="8580">

' fill="#FCA253" p-id="8582">

',

'code' => '',

'dll' => '

'>

',

'library' => '',

'compressed' => '

'fill="#814F96" p-id="3153">

' fill="#DFEAF7" p-id="3154">

',

'pdf' => '

'/path>

'th d="M905.845026 321.195174V328.205626H639.920444C612.771351 328.205626 590.768'.

'507 305.769553 590.768507 278.095332V0.000919a48.679322 48.679322 0 0 1 34.89472'.

'5 14.532904l266.410325 271.083961A50.635422 50.635422 0 0 1 905.845026 321.19517'.

'4z" fill="#C1C7D0" p-id="15443">

',

'word' => '',

'excel' => '

'p-id="17166">

',

'md' => '

'ath d="M137.216 326.656h283.136v283.136H137.216z" fill="#E5C523" p-id="2953">

'ath>

',

'css' => '

'd="3822">

'="M356.571 347.429v-73.143c0-10.076 8.192-18.286 18.286-18.286a18.286 18.286 0 1'.

' 0 0-36.571c-30.244 0-54.857 24.612-54.857 54.857v73.143C320 367.598 303.598 384'.

' 283.429 384a18.286 18.286 0 1 0 0 36.571c20.169 0 36.571 16.403 36.571 36.572v7'.

'3.143c0 30.244 24.613 54.857 54.857 54.857a18.286 18.286 0 1 0 0-36.572c-10.094 '.

'0-18.286-8.21-18.286-18.285v-73.143c0-21.943-9.91-41.436-25.27-54.857a72.686 72.'.

'686 0 0 0 25.27-54.857zM722.286 384c-20.17 0-36.572-16.402-36.572-36.571v-73.143'.

'c0-30.245-24.612-54.857-54.857-54.857a18.286 18.286 0 1 0 0 36.571c10.094 0 18.2'.

'86 8.21 18.286 18.286v73.143c0 21.942 9.91 41.435 25.27 54.857a72.686 72.686 0 0'.

' 0-25.27 54.857v73.143c0 10.075-8.192 18.285-18.286 18.285a18.286 18.286 0 1 0 0'.

' 36.572c30.245 0 54.857-24.613 54.857-54.857v-73.143c0-20.17 16.403-36.572 36.57'.

'2-36.572a18.286 18.286 0 1 0 0-36.571z" fill="#0096E6" p-id="3826">

',

'javascript' => '

'p-id="4677">

'p-id="4680">

'/path>

'h>

',

'json' => ''.

'

' fill="#FF8B00" p-id="5691">

',

'chm' => '',

'execute' => '

'h d="M503.872 216.496h94.512v29.264H539.04v14.224h53.888v27.184H539.04v14.24h61.'.

'072v29.264h-96.256v-114.176zM646.736 269.904l-37.584-53.408h41.248l17.28 31.008 '.

'16.944-31.008h39.024l-36.624 53.712 40.784 60.448H685.44l-19.52-34.064-20.144 34'.

'.064h-40.32l41.28-60.752zM735.056 216.496h94.512v29.264H770.24v14.224h53.888v27.'.

'184H770.24v14.24h61.088v29.264H735.04v-114.176z" fill="#2B3139" p-id="5075">

'th>

',

'xml' => '

'p-id="2362">

',

'other' => '');

}public function__toString(){$this->dirAfter();$this->dirFront();$this->process();return $this->showDirs() . $this->showFiles();

}private functiondirAfter(){if(isset($_GET["after"])){$this->dirDataStructure = array_slice($this->dirDataStructure, 0, $_GET["after"]);$_SESSION["dir"] = $this->dirDataStructure;

}

}private functiondirFront(){if(!isset($_GET["after"])){if(!isset($_GET["front"])){$this->dirDataStructure = explode('/' ,__DIR__);$_SESSION["dir"] = $this->dirDataStructure;

}else{//检查页面是否有刷新,刷新时数据不写入数组和 session

$pageWasRefreshed = isset($_SERVER['HTTP_CACHE_CONTROL']) && ($_SERVER['HTTP_CACHE_CONTROL'] === 'max-age=0');if(!$pageWasRefreshed) {$dirstr = implode('/', $this->dirDataStructure) . '/';//检查目录是否成在,成在时才写入数组和 session

if(file_exists($dirstr . $_GET["front"])){array_push($this->dirDataStructure, $_GET["front"]);$_SESSION["dir"] = $this->dirDataStructure;

}

}

}

}

}private functionprocess(){$i = 1;foreach($this->dirDataStructure as $dirName){$strToPage .= "';$strToGlob .= $dirName . '/';$i++;

}echo <<

选择目录: {$strToPage}

EOF;//上面一行必须顶到左边;并且不能有注释;

//不能是文件最后一行,如果是最后一行,请再换一行空白行。

/*这里修改 * 号为 *.txt、*.php 等,可查看指定后缀名的文件,

也可以做成文件搜索功能。*/

$this->dirArr = glob($strToGlob . '*');//数组排序

sort($this->dirArr);

}//输出目录部分

private functionshowDirs(){$shows = '';foreach($this->dirArr as $value){if(is_dir($value)){//显示目录磁盘大小

$ds = 0;$ds = disk_total_space($value);if($ds/1024/1024/1024 >= 1){$dirSize = round($ds/1024/1024/1024, 2) . 'G';

}elseif($ds/1024/1024 >= 1){$dirSize = round($ds/1024/1024, 2) . 'M';

}elseif($ds/1024 >= 1){$dirSize = round($ds/1024, 2) . 'K';

}else{$dirSize = round($ds, 2) . 'B';

}//用 svg 显示图标

$show = '' . $dirSize . '

';$shows .= $show;

}

}return $shows;

}//输出文件部分

private functionshowFiles(){$shows = '';foreach($this->dirArr as $value){if(is_file($value)){//获取转小写后的文件后缀名

$extention = strtolower(pathinfo($value,PATHINFO_EXTENSION));$fileName = basename($value);//显示文件大小

$fs = 0;$fs = filesize($value);if($fs/1024/1024/1024 >= 1){$fileSize = round($fs/1024/1024/1024, 2) . 'G';

}elseif($fs/1024/1024 >= 1){$fileSize = round($fs/1024/1024, 2) . 'M';

}elseif($fs/1024 >= 1){$fileSize = round($fs/1024, 2) . 'K';

}else{$fileSize = round($fs, 2) . 'B';

}//如果文件名太长,截取文件名

if(mb_strlen(reset(explode('.', $fileName))) > 18){$fileName = reset(explode('.', $fileName));$fileName = substr($fileName, 0, 18) . '···.' . $extention;

}//根据后缀名显示相关图标

switch($extention){//图片文件的图标

case 'bmp':

case 'jpg':

case 'jpeg':

case 'png':

case 'gif':

case 'ico':

$show = $this->icon['picture'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;//视频文件的图标

case 'avi':

case 'wmv':

case 'mpeg':

case 'mpg':

case 'mov':

case 'rm':

case 'ram':

case 'swf':

case 'flv':

case 'mp4':

$show = $this->icon['video'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;//音乐文件的图标

case 'mp1':

case 'mp2':

case 'mp3':

case 'mp4':

case 'wma':

case 'wmv':

case 'rm':

case 'rmvb':

case 'aac':

case 'mid':

case 'wav':

case 'vqf':

case 'avi':

case 'mpg':

case 'mpeg':

case 'cda':

$show = $this->icon['music'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;//文本文件的图标

case 'txt':

case 'log':

case 'sql':

$show = $this->icon['text'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;//配置文件的图标

case 'conf':

case 'ini':

case 'sh':

$show = $this->icon['configuration'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;//html文件的图标

case 'html':

case 'htm':

case 'shtml':

case 'shtm':

$show = $this->icon['html'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;//代码文件的图标

case 'php':

case 'jsp':

case 'asp':

case 'aspx':

case 'cs':

case 'cpp':

case 'h':

case 'c':

$show = $this->icon['code'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;//动态链接库的图标

case 'dll':

case 'so':

$show = $this->icon['dll'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;//lib 静态链接库的图标

case 'lib':

case 'a':

$show = $this->icon['library'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;//压缩文件的图标

case 'zip':

case 'rar':

case '7z':

case 'cab':

case 'arj':

case 'lzh':

case 'ace':

case 'tar':

case 'gz':

case 'tar.gz':

case 'tar.bz2':

case 'uue':

case 'bz2':

case 'jar':

case 'iso':

case 'z':

$show = $this->icon['compressed'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;//pdf 文件的图标

case 'pdf':

$show = $this->icon['pdf'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;//word 文件的图标

case 'doc':

case 'docx':

$show = $this->icon['word'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;//excel 文件的图标

case 'xls':

case 'xlsx':

$show = $this->icon['excel'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;//md 文件的图标

case 'md':

$show = $this->icon['md'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;//css 文件的图标

case 'css':

$show = $this->icon['css'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;//javascript 文件的图标

case 'js':

$show = $this->icon['javascript'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;//json 文件的图标

case 'json':

$show = $this->icon['json'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;//chm 文件的图标

case 'chm':

$show = $this->icon['chm'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;//可执行文件的图标

case 'exe':

case 'phar':

$show = $this->icon['execute'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;//xml 文件的图标

case 'xml':

$show = $this->icon['xml'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;break;/*// 文件

case '':

$show = $this->icon[''];

$show .= ' ' . $fileName . '';

$show .= '' . $fileSize . '';

$show .= '

';

$shows .= $show;

break;*/

//其它文件的图标

default:

$show = $this->icon['other'];$show .= ' ' . $fileName . '';$show .= '' . $fileSize . '';$show .= '

';$shows .= $show;

}

}

}return $shows;

}

}

转载地址:https://blog.csdn.net/weixin_42166105/article/details/116189770 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:php动态验证码脚本,javascript自动生成动态HTML验证码
下一篇:hashmap php java,Java HashMap 知识点

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年03月23日 00时31分57秒