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.