FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free 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
Installing a SMF based forum
HUGE FREE LINK EXCHANGE!!
[Resolved] Object Orientated PHP errors
300 FREE Backlinks - Climb The Ranks!
SSI within php coded files
PHPNuke installation problem
Php Maximun Files Upload?
php - access root directory
PhpNuke Installation Tutorial
How many files are in a directory?
Connected to another part of a php script.
Anonymous logins to FTP
Dragonfly install tutorial
PHP 5.4.0 Release Announcement
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

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