Reading files in a directory?

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
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

Reading files in a directory?

Post by William »

Code: Select all

<?php
$dirname = "/home/william/public_html/enews/templates";
$dh = opendir( $dirname ) or die("");

while ( $file = readdir( $dh ) ) {
	print "<option value="templates/$file/template.htm">$file</option>";
}
Closedir( $dh );
?>
Is my coding ity acces lots it will allow people tyo upload themes and it will auto be able to be used .ect but when it reads the templates folder.... it puts ., .., ..., .ect and then files... Is there anyway i can make that go away? thanks.
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Use is_file() to check if it a file, if it is, echo the option, else do nothing.

-Nay
User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

Post by William »

lol, I want it to show a list of files not check if its a file... Im making somthing that is going to make a list of html options into a form buy getting ithe info and directory information in a folder so all you do is upload a theme intoa folder and you can install it with out having to go into script jsut upload and go...
Post Reply