• PHP 简易文件查看器


    超简易服务器端文件查询器

    代码如下:

    <?php
    
    // 系统入口
    date_default_timezone_set("PRC");
    error_reporting(E_ALL & ~E_NOTICE);
    set_time_limit(30);
    
    define('DS', DIRECTORY_SEPARATOR);
    define('ROOT_PATH', dirname(__FILE__) . DS);
    
    // 登录
    if ($_SERVER['PHP_AUTH_USER'] != 'admin' || $_SERVER['PHP_AUTH_PW'] != '123')
    {
        header('WWW-Authenticate: Basic realm="用户登录"');
        header('HTTP/1.0 401 Unauthorized');
        die("未登录");
    }
    
    $cur_path = $_GET['path'] ?: dirname(__FILE__);
    $cur_path = realpath($cur_path);
    if (is_file($cur_path))
    {
        header('Content-type: text/plain; charset=utf-8');
        echo file_get_contents($cur_path);
        exit;
    }
    
    $pre_path = dirname($cur_path);
    $list = glob($cur_path . DS . '*');
    
    header('Content-type: text/html; charset=utf-8');
    header('Cache-Control: no-cache, must-revalidate, max-age=0');
    header('Pragma: no-cache');
    ?>
    <!DOCTYPE html>
    <head>
    <title>文件管理</title>
    </head>
    <body style="font-family: consolas">
        <div><?=$cur_path?></div>
        <table border="1" cellspacing="0" cellpadding="5">
            <tr>
                <td></td>
                <td><a href='zfile.php?path=<?=urlencode($pre_path) ?>'>..</a></td>
                <td></td>
            </tr>
            <?php foreach ($list as $r) { $t = filetype($r); ?>
                <tr>
                    <td><?=$t?></td>
                    <td><a target="<?=($t=='file'?'_blank':'')?>" href='zfile.php?path=<?=urlencode($cur_path) ?><?=DS.urlencode(basename($r))?>'><?=basename($r)?></a></td>
                    <td><?=round(filesize($r)/1024)?>k</td>
                </tr>
            <?php } ?>
        </table>
    </body>
  • 相关阅读:
    basis 文档
    profile default1
    profile default
    2101244
    Linux下对lvm逻辑卷分区大小的调整(针对xfs和ext4不同文件系统)
    1816647
    lvm管理:扩展lv、删除pv、lv等
    HPUX and AIX SSH 互信
    SLD Related Gateway Serivces Unavaliable
    [原创]K8 MSF Bind Shell TCP 连接工具
  • 原文地址:https://www.cnblogs.com/zjfree/p/11301388.html
Copyright © 2020-2023  润新知