Display Listing of all files in a directory
-
I’m trying to display the contents of a directory folder with about 100 pdf files in it. I’d like to have a Page that would automatically display new files after I add them to the directory. Of course, the user should be able to either view or dl the files.
I’ve read the docs on WP Pages and I’ve also found this:
https://www.ads-software.com/support/topic/103039?replies=3I think (besides being elderly, I’m not even sure) my problem is that I don’t know how to incorporate the php code into the Page. Pasting it as code sure didn’t work. I have this code from a php tutorial:
<?php function showContent($path){ if ($handle = opendir($path)) { $up = substr($path, 0, (strrpos(dirname($path."/."),"/"))); echo "<tr><td colspan='3'>"; echo "<a href='".$_SERVER['PHP_SELF']."?path=$up'>Up one level</a>"; echo "</td></tr>"; while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $fName = $file; $file = $path.'/'.$file; if(is_file($file)) { echo "<tr><td> -F- <a href='".$file."'>".$fName."</a></td>" ."<td align='right'>".date ('d-m-Y H:i:s', filemtime($file))."</td>" ."<td align='right'>".filesize($file)." bytes</td></tr>"; } elseif (is_dir($file)) { print "<tr><td colspan='3'> -D- <a href='".$_SERVER['PHP_SELF']."?path=$file'>$fName</a></td></tr>"; } } } closedir($handle); } } ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Display Listing of all files in a directory’ is closed to new replies.