Results 1 to 4 of 4

Thread: PHP script modification to make it a list instead of

  1. #1
    Join Date
    Jan 2011
    Location
    Southeastern CT
    Posts
    612
    Thanks
    46
    Thanked 32 Times in 32 Posts

    Default PHP script modification to make it a list instead of

    a bunch of stuff run together

    Hi folks I found a small directory lister script.

    Code:
    <?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
    Last edited by ajfmrf; 08-07-2011 at 01:31 AM. Reason: misatake

  2. #2
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Try this:

    PHP Code:
    $dir opendir("dir");
        
    while(
    $row readdir($dir)) {
        echo 
    $row."<BR>\n";
    }

    closedir($handler); 
    - Josh

  3. #3
    Join Date
    Jan 2011
    Location
    Southeastern CT
    Posts
    612
    Thanks
    46
    Thanked 32 Times in 32 Posts

    Default I got these errors

    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

  4. #4
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    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.

    PHP Code:
    $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 "./".
    - Josh

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •