Page 1 of 1

PHP code to List folder contents as HTML hyperlinks

Posted: Sun Dec 06, 2009 9:17 am
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

Re: PHP code to List folder contents as HTML hyperlinks

Posted: Tue Dec 08, 2009 5:23 pm
by AbraCadaver
Is the file extension .php? The webserver probably won't parse the PHP code if not.