最简易的PHP网盘系统/单位文件下载小功能页面
遍历目录下的.rar格式文件,显示到网页提供下载
FTP上传压缩包到文件夹下,就可以显示到文件供访问下载。
<?php
/*
//最简易的PHP网盘系统/单位文件下载小功能页面
//遍历目录下的.rar格式文件,显示到网页提供下载
//FTP上传压缩包到文件夹下,就可以显示到文件供访问下载。
*/
error_reporting(0);
header('Content-Type: text/html; charset=utf-8');
?>
<style>
h1{font-size:24px;line-height:180%;font-weight:600;margin:4px 8px;color:red;}
h2,b{font-size:20px;line-height:160%;font-weight:600;margin:3px 6px;color:green;}
h3{font-size:16px;line-height:140%;font-weight:600;margin:2px 4px;color:blue;}
h4{font-size:14px;line-height:120%;font-weight:300;margin:1px 2px;color:black;}
a{text-decoration:none;}
a:link{color:blue;}
a:visited{color:blue;}
a:hover,a:active{background:#0180CF;color:white;}
table{border-left:1px solid #a2c6d3;border-top:3px solid #0180CF; margin:15px auto;}
table{width:88%;min-width:555px;max-width:888px;}
table td{border-right:1px solid #a2c6d3;border-bottom:1px solid #a2c6d3;}
table td{padding:2px;word-wrap:break-word;word-break:break-all;}
.tt{background:#e5f2fa;line-height:18px;FONT-SIZE:12px;text-align:center;}
.rr{background:#e5f2fa;line-height:18px;FONT-SIZE:12px;text-align:center;}
</style>
<?php
function charaget($data){
if(!empty($data) ){
$fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ;
if( $fileType != 'UTF-8'){
$data = mb_convert_encoding($data ,'utf-8' , $fileType);
}
}
return $data;
}
function characet($data){
if(!empty($data) ){
$fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ;
if( $fileType != 'GBK'){
$data = mb_convert_encoding($data ,'GBK' , $fileType);
}
}
return $data;
}
function my_scandir($dir){
$ii=0;
if ( $handle = opendir($dir) ) {
while ( ($file = readdir($handle)) !== false ) {
if ( $file != ".." && $file != "." ) {
if ( is_dir($dir . $file. "/" ) ) {
$filep = $dir . $file . "/";
$filep = charaget($filep);
$filea = charaget($file);
$decho = my_scandir($dir . $file. "/" );
}else{
$filep = $dir . $file;
$filet = substr($file,-4);
$filep = charaget($filep);
$filea = charaget($file);
if(stristr("-.rar-.zip-","-{$filet}-")){
$ii++;
$filesize = filesize($filep);
$filetime = date("Y-m-d H:i:s",filectime($filep));
$fileedit = date("Y-m-d H:i:s",filemtime($filep));
if (is_file($filep)){
}else{
}
$fecho.="<tr><td colspan=\"4\"><a href='{$filep}' target='_blank'><h3>{$filea}</h3></a>
</td></tr>";
}else{
//echo "<h4>$file</h4>";
}
}
}
}
closedir($handle);
if($ii>0){
$iecho = "<tr class=\"rr\"><td colspan=\"4\"><b>{$dir}</b></td></tr>\r\n";
return $iecho . $fecho .$decho ;
}else{
return "<tr><td colspan=\"4\"><h2>文件夹<b>{$dir}</b>下没有文件</h2></td></tr>\r\n";
}
}
}
echo "<table cellspacing=\"0\" class=\"table\" cellpadding=\"0\">\r\n";
$fd = trim($_GET['f']);
if(strlen($fd)<1){ $fd="./"; }else{ $fd=$fd;}
echo my_scandir($fd);
echo "</table>\r\n";
?>