display .inc files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

display .inc files

Post 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.
will
Forum Contributor
Posts: 120
Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN

Post 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
Opix
Forum Newbie
Posts: 4
Joined: Sun Jun 30, 2002 5:52 am
Location: Behind you!
Contact:

Post 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.
Post Reply