PDA

View Full Version : Need to display files/directorys within a directory


Jalrock
05-27-2003, 11:11 PM
thanks in advance

Jalrock
05-28-2003, 12:14 AM
This displays every directory/file within the $dir. Weird that it pulls 2 directorys that are just one and 2 dots. (. &..) anyone know what this is and how to get rid of it?


<?php
include "header.inc";
$dir = "/dir Name/";


if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {

print "<a href=\"/index.php?selectusername=$file\">$file 's Photo page</a> <br>\n";
}
closedir($dh);
}
}

?>

Black Vivi
05-28-2003, 10:13 PM
try this:

<?php
include "header.inc";
$dir = "/dir Name/";


if (is_dir($dir))
{
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
if (($file != "..") || ($file != ".")
{
echo("<a href=\"/index.php?selectusername=$file\">$file 's Photo page</a> <br>\n");
}
}
closedir($dh);
}
}

?>

if that dunt work ive got anuther one that i kno will

filburt1
05-28-2003, 10:14 PM
Better yet, try looking at the PHP docs. They give an example right there, so "search and ye shall" find scores another victory! :)