Page 1 of 1

display .inc files

Posted: Sat Jun 29, 2002 11:03 pm
by Sevengraff
Arg, i need help. I need a script that will show the contents of a dir, and only link out .inc files. I tryed making my own, but i dont know enough.

Posted: Sun Jun 30, 2002 6:43 am
by will
link out? you mean you want .inc files to be hyperlinks, but the others to be just text?

try looking at example 1 on
http://www.php.net/manual/en/function.opendir.php

and read this to differentiate between .inc files and the others
http://www.php.net/manual/en/function.pathinfo.php

Posted: Sun Jun 30, 2002 7:39 am
by Opix

Code: Select all

<?
$yourdir = "Directory";
$dir = opendir($yourdir);
$table = "<table width="50%" border="1" align="center">";
while ($viewFile = readdir($dir)) &#123;
if (($viewFile != ".") && ($viewFile != "..")) &#123;

if ($viewFile =~ ".inc") &#123;
$table .= "<tr><td><a href="$viewFile">$viewFile</a></td></tr>";
&#125;
else &#123;
$table .= "<tr><td>$viewFile</td></tr>";
&#125;
&#125;
&#125;
$table .= "</table></td></tr></table>";
?>
Haven't tested it, but that should work.