PHP code to List folder contents as HTML hyperlinks

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
Subs
Forum Newbie
Posts: 1
Joined: Sun Dec 06, 2009 9:00 am

PHP code to List folder contents as HTML hyperlinks

Post by Subs »

Hi,

I have my PHP 5 running in IIS 6.0. I have my application hosted on IIS. I need to list all the contents of a specific folder in the server as as hyperlinks in my HTML. I was trying to use the PHP code. But, it does not work when I embed in the HTML.

Is there a better way to embed PHP in HTMLs?
Please help me with the php code that serves this purpose.

$dir = opendir('files/');
echo '<ul>';
while ($read = readdir($dir)) {
if ($read!='.' && $read!='..') {
echo '<li><a href="files/'.$read.'">'.$read.'</a></li>';
}
}
echo '</ul>';
closedir($dir);

_____ERROR_____________
.$read.''; } } echo '
'; closedir($dir); ?>
_________________________

Thanks.
Subs
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP code to List folder contents as HTML hyperlinks

Post by AbraCadaver »

Is the file extension .php? The webserver probably won't parse the PHP code if not.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply