dtcyv3985 2016-09-12 21:19
浏览 11

用权限监听PHP目录

I have a webpage (apache2) which is based on Linux ubuntu server 14.04 LTS (32bit).

I successfully found, according to me, a good and simple PHP directory/file listener.

My problem is: I don't know how to show the directories/files which have 0700 permission. I also would like to open the file. I don't want to change the permissions because on my webpage, the users have to login to use the website. I mean the files which have 0700 permission are not public, and I want that just the members of the website can use/download the files.

My code is:

<?php
    $dirlist = getFileList("./uf/");
?>
<table border="1">
<thead>
<tr><th>Name</th><th>Type</th><th>Size</th><th>Last Modified</th></tr>
</thead>
<tbody>
<?PHP
        // output file list as table rows
        foreach($dirlist as $file) {
        echo "<tr>
";
        echo "<td><a href=\"{$file['name']}\">",basename($file['name']),"</a></td>
";
        echo "<td>{$file['type']}</td>
";
        echo "<td>{$file['size']}</td>
";
        echo "<td>",date('r', $file['lastmod']),"</td>
";
        echo "</tr>
";
    }
?>
</tbody>
</table>
<?php
    function getFileList($dir, $recurse=false)
    {
        $retval = array();

        // add trailing slash if missing
        if(substr($dir, -1) != "/") $dir .= "/";

        // open pointer to directory and read list of files
        $d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
        while(false !== ($entry = $d->read())) {
            // skip hidden files
            if($entry[0] == ".") continue;
            if(is_dir("$dir$entry")) {
                $retval[] = array(
                "name" => "$dir$entry/",
                "type" => filetype("$dir$entry"),
                "size" => 0,
                "lastmod" => filemtime("$dir$entry")
                );
                if($recurse && is_readable("$dir$entry/")) {
                    $retval = array_merge($retval, getFileList("$dir$entry/", true));
                }
            } elseif(is_readable("$dir$entry")) {
                $retval[] = array(
                "name" => "$dir$entry",
                "type" => mime_content_type("$dir$entry"),
                "size" => filesize("$dir$entry"),
                "lastmod" => filemtime("$dir$entry")
            );
            }
        }
        $d->close();

        return $retval;
    }
?>

I hope you can understand what I'm talking about.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算