Php Programming Code Examples
Php > Directories Code Examples
Grab directory listings into an array the example prints out each
Grab directory listings into an array the example prints out each
<html>
<head>
<title>SHOW DIRS</title>
</head>
<body>
<?
#this is the directory you want to index
$startdirname = "/home/sites/site7/pics/";
#if you want to work in the current dir, uncomment the next line
//$startdirname= exec("pwd");
#this is the extension of the files you want to play with
#standard UNIX and derivatives wildcards are allowed
$ext = "jpg";
$dir = exec("ls -l $startdirname", $allentries,$dead);
for ($index=0; $index<count($allentires); $index++){
echo " $allentries[$index] <BR>";
}
#$dir = dir(".");
$dir = dir("$startdirname");
while ($file = readdir($dir)){
if ( !eregi ("(^\.)|(*\.)", $file) ) {
$dirs[] = $file;
$dirnumber = count($dirs);
}
}
echo "<HR>";
for ($i=0; $i < $dirnumber; $i++){
echo $dirs[$i];
echo "<hr>";
}
?>
</body>