Log in

View Full Version : PHP script modification to make it a list instead of



ajfmrf
08-07-2011, 01:30 AM
a bunch of stuff run together

Hi folks I found a small directory lister script.



<?php
$row = exec('dir',$output,$error);
while(list(,$row) = each($output)){
echo $row, "<BR>\n";
}
if($error){
echo "Error : $error<BR>\n";
exit;
}
?>


It lists files and folders all runinning to each other except for one single break.

Can this be modified to have one file/folder to each line in a list form?

I tried to add another <br> in it but I got errors each way I tried it.

Thanks,

Bud

JShor
08-07-2011, 01:46 AM
Try this:



$dir = opendir("dir");

while($row = readdir($dir)) {
echo $row."<BR>\n";
}

closedir($handler);

ajfmrf
08-08-2011, 12:24 AM
with that code

Warning: opendir(dir) [function.opendir]: failed to open dir: No such file or directory in ,,,,,,,,,,,/menu/php/blist.php on line 2

Warning: readdir() expects parameter 1 to be resource, boolean given in .........../menu/php/blist.php on line 4

Warning: closedir() expects parameter 1 to be resource, null given in /menu/php/blist.php on line 8

JShor
08-08-2011, 01:29 AM
The argument in the opendir() function is supposed to be the name of the directory you're trying to list. Since you had "dir" in the other script, I assumed that "dir" was the directory you're trying to list.



$dir = opendir("dir");


Replace it with the name that you're trying to list. If you're trying to list the parent directory, set the argument to "./".