[Pmwiki-users] Alternative version of FmtUploadList
Christian Ridderström
chr
Sun Nov 30 12:17:30 CST 2003
Hi
Below is a modified version of FmtUploadList() that makes [[Attachlist]]
also show the contents of subdirectories, see here for an example:
http://wiki.lyx.org/pmwiki.php/Layouts/Layouts?action=upload
And below is the new code... comments are most welcome since I've never
programmed in PHP before. Maybe I should learn PHP :-)
function FmtUploadList($pagename,$order='N=A') {
global $UploadDir,$UploadPrefixFmt,$UploadUrlFmt,$TimeFmt;
$dir = FmtPageName("$UploadDir$UploadPrefixFmt",$pagename);
$url = FmtPageName("$UploadUrlFmt$UploadPrefixFmt",$pagename);
if ($order=='') $order='N=A';
// The substr() below removes the trailing '/'
return FmtUploadDir(substr($dir,0,-1), substr($url,0,-1), $order);
}
function FmtUploadDir($dir,$url,$order) {
global $TimeFmt;
$dirp = @opendir($dir);
$out = '';
if (!$dirp) return $out;
$filelist = array();
while (($file=readdir($dirp)) !== false) {
if ($file[0]=='.') continue;
switch (strtolower($order[0])) {
case 'm': $filelist[$file]=filemtime("$dir/$file"); break;
case 's': $filelist[$file]=filesize("$dir/$file"); break;
default: $filelist[$file]=$file; break;
}
}
closedir($dirp);
if (strtolower($order[2])=='d') arsort($filelist); else asort($filelist);
foreach($filelist as $file=>$x) {
$stat = stat("$dir/$file");
$out .= "<li> ";
if(is_dir("$dir/$file"))
$out .= "$file/ . . . . . . . ".strftime($TimeFmt,$stat['mtime'])
."<ul>\n".FmtUploadDir("$dir/$file", "$url/$file", $order)."</ul>";
else
$out .= "<a href='$url/$file'>$file</a> ... "
.$stat['size']." bytes ... ".strftime($TimeFmt,$stat['mtime']);
$out .= "\n</li>";
}
return $out;
}
/Christian
--
Dr. Christian Ridderstr?m, +46-8-768 39 44 http://www.md.kth.se/~chr
More information about the pmwiki-users
mailing list