file - PHP directory listening with permissions -
i have webpage (apache2) based on linux ubuntu server 14.04 lts (32bit).
i found, according me, , simple php directory/file listener.
my problem is: don't know how show directories/files have 0700 permission. open file. don't want change permissions because on webpage, users have login use website. mean files have 0700 permission not public, , want members of website can use/download 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 table rows foreach($dirlist $file) { echo "<tr>\n"; echo "<td><a href=\"{$file['name']}\">",basename($file['name']),"</a></td>\n"; echo "<td>{$file['type']}</td>\n"; echo "<td>{$file['size']}</td>\n"; echo "<td>",date('r', $file['lastmod']),"</td>\n"; echo "</tr>\n"; } ?> </tbody> </table> <?php function getfilelist($dir, $recurse=false) { $retval = array(); // add trailing slash if missing if(substr($dir, -1) != "/") $dir .= "/"; // open pointer directory , read list of files $d = @dir($dir) or die("getfilelist: failed opening directory $dir 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 can understand i'm talking about.
Comments
Post a Comment