FRIHOSTFORUMSSEARCHFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

req: PHP to list files in directory, and link to them

 


gonzo
I asume that since PHP runs either as nobody or my UID that it's not bound by apache options imposed on the surfing user. As such it should be able to interact with all files as I would via FTP. Given that is there a simple bit of PHP that can create a list of all the files in the current directory and output an HTML list of links to them?


thanks
Bondings
You should search on google for this. There are really tons of information about php functions if you know how to search for them and combine every little bit.
http://www.google.be/search?q=php+list+files

This is what I found. It is not exactly what you asked, but you can easily modify it, iMHO.

Code:
<?
/*
  ABOUT:
  This snippet will list all the files in the directory of your
  choice, truncate the file extension, capitalize the first letter and
    put it all in a drop down menu. The script will not list subdirectories so
    all you see are the files in your directory.
   
    Feel free to use or modify to your liking.
   
    USAGE:
    Change the $dirpath variable the directory you want to list.

    AUTHOR:
  Written by shockingbird
  Visit www.glomer.net for more information
  tate at tatenations dot com for any questions
*/
    echo "<form>";
//Looks into the directory and returns the files, no subdirectories
    echo "<select name='yourfiles'>";
//The path to the style directory
    $dirpath = "/path/to/your/directory";
    $dh = opendir($dirpath);
       while (false !== ($file = readdir($dh))) {
//Don't list subdirectories
          if (!is_dir("$dirpath/$file")) {
//Truncate the file extension and capitalize the first letter
           echo "<option value='$file'>" . htmlspecialchars(ucfirst(preg_replace('/\..*$/', '', $file))) . '</option>';
   }
}
     closedir($dh);
//Close Select
echo "</select>";
echo "</form>";
?>
Related topics

Php Maximun Files Upload?
php - access root directory
PhpNuke Installation Tutorial
Dragonfly install tutorial
Installing a SMF based forum

HUGE FREE LINK EXCHANGE!!
[Resolved] Object Orientated PHP errors
SSI within php coded files
300 FREE Backlinks - Climb The Ranks!
PHPNuke installation problem

Connected to another part of a php script.
Anonymous logins to FTP
How many files are in a directory?
Error I can't seem to fix.
Frame Effect Without Frames! (PHP)
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.