php实现文件夹访问,最基础,php在线文件管理系统

版权声明:本文为博主原创文章,转载请注明出处:http://blog.csdn.net/sinat_34820292 https://blog.csdn.net/sinat_34820292/article/details/78601605


php实现的文件夹浏览:
这里写图片描述

<?php
define('ROOTPATH','/tftp/data/');
$spath = isset($_REQUEST)&&isset($_REQUEST['path'])?$_REQUEST['path'].'/':'';
$path = ROOTPATH.$spath;
echo '<hr/>'.xls($path);


// 扫描文件夹子项目
function ls($path){
    if(is_dir($path)){
        return scandir($path);
    }
    return [];
}

// 文件夹信息可视化
function xls($path){
    $dir = ls($path);
    $str = '<table class="fileList">';
    $str .= "<thead><caption><input type=\"text\" value=\"$path\"></caption>";
    $str .= '<th>选择<input type="checkbox"></th>';
    $str .= '<th>名称</th><th>类型</th><th>大小kb</th></thead><tbody>';
    foreach($dir as $index=>$in){
        if(is_dir($path.$in)){
            $str .= '<tr><td><input type="checkbox" disabled></td><td>'.$in.'/</td><td>dir</td><td>--</td><tr>';
        }elseif(is_file($path.$in)){
            $handle = fopen($path.$in,"r");
            $str .= '<tr><td><input type="checkbox"></td><td>'.$in.'</td><td>'.
            getFileType($path.$in).'</td><td>'.round(filesize($path.$in)).'kb</td><tr>';
        }
    }
    $str .= '</tbody></table>';
    return $str;
}

// 根据扩展名判断文件类型
function getFileType($filePath) {
   $exten = explode('.', $filePath);
   return strtolower(end($exten));
}

造轮子造一半,发现有很好的轮子,所以不造了。

一款不错的PHP在线文件管理系统,PHP WEBFTP,挺好用,推荐使用

名字:kodexplorer

官方地址:http://www.kalcaddle.com/

猜你喜欢

转载自blog.csdn.net/sinat_34820292/article/details/78601605