Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    get all files in a folder and list them

    im not shure if there is another easier way to do this without php.. anyways,

    i have a bunch of files in a folder and i want a script that will scan the folder and display all of the files in that folder, then display all of those files in an html document so that i can download whatever file i want.

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    PHP Code:
    $skip_folders = array('.','..','ANY OTHER FILES/FOLDERS YOU WANT SCRIPT TO HIDE');
    $dir /*PATH TO DIRECTORY*/
       
    if (is_dir($dir))
        {
         if (
    $dh opendir($dir))
          {
           while ((
    $file readdir($dh)) !== false)
           {
                if(!
    in_array($file$skip_folders))
                {
                    print(
    "<li><a href=\"$file\">$file</a></li>");
                }
            }
           }
          
    closedir($dh);
         } 
    Edit: I forgot to do this last night, but for valid and working HTML, you should put <ul> and </ul> tags around the script. Sorry for leaving that out


    HTH,
    Dan
    Last edited by whizard; 01-08-2007 at 04:45 PM.
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    New Coder
    Join Date
    Jan 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you very much

  • #4
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    No Problem!!



    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION


  •  

    Posting Permissions

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