Version: 1.0

Type: Full Script

Category: File Management

License: Other

Description: Allows drag & drop additions to a website. Lists all directories and files and creates links. I wrote this so various departments could add public documents to our internal website, with no html maintenance, by dropping them into a public area. (icons not included.)



<?
/* This script allows drag & drop additions to a web site by creating links
   based on directory structure. It is purposefully designed to work only
   within the directory scope of the webserver.

   Written by Jack Kelly Dobson - jdobson@mailbag.com

   Released under the "Please give credit where credit is due" license agreement.
*/


function Check_For_Slash($path) {
   if (substr($path, (strlen($path) - 1), 1) != "/") {
      $path = $path . "/";
   }
   return($path);
}

function Get_Directory_Listing($path) {
   $base_dir = $_SERVER["DOCUMENT_ROOT"]; // all paths will be relative to webserver.
   $base_dir = Check_For_Slash($base_dir);
   if ($dir_handle = opendir($base_dir . $path)) {
      while ($file = readdir($dir_handle)) {
         $path = Check_For_Slash($path);
         if (($file != ".") && ($file != "..")) {
            chdir($base_dir . $path);
            if (is_dir($file)) {
               print("<A HREF='" . $_SERVER["PHP_SELF"] . "?PATH=" . $path . $file . "'><IMG BORDER='0' SRC='/images/icons/folder.gif'> " . $file . "</IMG></A><BR>");
            }
         }
      }
      closedir($dir_handle);
   }
   if ($dir_handle = opendir($base_dir . $path)) {
      while ($file = readdir($dir_handle)) {
         $path = Check_For_Slash($path);
         chdir($base_dir. $path);
         if (($file != ".") && ($file != "..")) {
            if (is_file($file)) {
               print("<A HREF='" . $path . $file . "'>");
               if (substr($file, strlen($file) - 3, 3) == "xls") {
                  print("<IMG BORDER='0' SRC='/images/icons/excel.gif'>");
               }
               elseif(substr($file, strlen($file) - 3, 3) == "doc") {
                  print("<IMG BORDER='0' SRC='/images/icons/word.gif'>");
               }
               elseif(substr($file, strlen($file) - 3, 3) == "ppt") {
                  print("<IMG BORDER='0' SRC='/images/icons/powerpoint.gif'>");
               }
               else {
                  print("<IMG BORDER='0' SRC='/images/icons/page.gif'>");
               }
               print(" " . $file . "</IMG></A><BR>");
            }
         }
      }
      closedir($dir_handle);
   }
}

if (!IsSet($_GET["PATH"])) {
   $_GET["PATH"] = "";  //Set this to the directory you want to display.
                        // Leave blank for document root.
   }
   Get_Directory_Listing($_GET["PATH"]);
?>