________________________________________________ Cet indexeur de fichiers créé en php par Brian Donovan, www.lophty.com est bien pratique pour éviter d'avoir l'horrible page "Index of..." noire et blanche par défaut des serveurs Apache. Elle permet une complète personnalisation des couleurs par une feuille de styles CSS fournie, et d'être traduite. Il suffit de recopier le répertoire indexerfiles et l'index.php dans chacun de vos répertoires à lister. Voici son code complet, version 1.5.1 : v 1.0 # Tim Waugh (tim@cyberelk.net, http://www.cyberelk.net/tim/) # Added support for multi-dot file names (ex. stuff.under.mytoenail.foo as # opposed to single-dot file names like stuff.foo) # #Jan 05, 2002 => v 1.5 # I added more flexibility to file listing inclusion/exclusion - can # now choose to include only files with specific extensions in # listings or to list all files, excluding those with specific # extensions. Added option to block listing of all subdirectories. # Changed var names to make variable types more obvious (ie # $arrSomeArray instead of $someArray). # # July 13, 2002 => 1.5.1 # Fixed sorting. There was a typo in isortMultiD that shortcircuted # sorting. #============================================= # == Notes (below) ================================ #============================================= # # $strThisFileName : the name of this file # # $thisDirectory : the path to the directory in which this page sits. # For Apache-served sites, you can use the predefined # $REQUEST_URI variable. Note that you can also specify a string, # like a full url, but this will not affect the directory that's actually # indexed. :D # # $strThisPageFilesDir : the name of a directory in which we'll put the # css file and gifs that we need to beautify this page Note that you # don't have to put those files into a directory separate from this # file. I just do it to make global changes for all of these indexing # pages possible - by putting the css file and gifs into a folder and # then giving $strThisPageFilesDir the value of the path to that folder, # you can update the bullets or the general appearance of the page # by changing a few files in one location. If you want to put these # files into the same directory as this page, that's fine - just give # $strThisPageFilesDir a value of "" # # $arrBulletImgs : holds the filenames of the images used as bullets # # Finally, remember to change the permissions on subdirectories that # will be listed by this script if you would like visiors to be # able to drill down into them #============================================= $strThisFileName = "index.php"; $strThisDirectoryPath = $REQUEST_URI; $strThisServerName = $SERVER_NAME; $strThisPageFilesDir = "indexerfiles/"; $strThisPageCssFile= $strThisPageFilesDir ."dirindexer.css"; $arrFileImgProps = array('filepath' => $strThisPageFilesDir ."file.gif", 'height' => '13', 'width' => '13'); $arrDirImageProps = array('filepath' => $strThisPageFilesDir ."dir.gif", 'height' => '13', 'width' => '13'); $arrBulletImgs = array('fileImg' => $arrFileImgProps, 'dirImg' => $arrDirImageProps); #--------------------------------------------------- # Add the name of this file and the namess of the files and dirs used # with it to arrays. When the files and directories are read in, files # and dirs in these 2 arrays will not by listed or counted when this # page is viewed. If there are any other files other than those # actually used by this page that you'd rather not have so readily # available to others through this page, you can add them into these # arrays #--------------------------------------------------- $arrDontListFiles = array($strThisFileName, $arrBulletImgs['dirImg']['filepath'], $arrBulletImgs['fileImg']['filepath'], $strThisPageCssFile); $arrDontListDirs = array($strThisPageFilesDir , "cgi-bin", "indexerfiles"); #--------------------------------------------------- # Below are two array declarations. These array declarations should # contain only string values corresponding to file extensions. # # Ex. $arrDontListFilesExts = array("jpeg", "jpg", "gif"); # # Files with extensions listed in the $arrDontListFilesExts array # will not be shown. If you include any extension strings in the # $arrListOnlyFilesExts array, then *ONLY* files with those # extensions will be shown. # # Note : use lower case extensions, i.e. txt, not TXT # # Ex. (1.) # # $arrDontListFilesExts = array(); # $arrListOnlyFilesExts = array(); # # result : all files (other than any listed in $arrDontListFiles) # will be shown and counted. # # # Ex. (2.) # # $arrDontListFilesExts = array("php"); # $arrListOnlyFilesExts = array(); # # result : all files (other than any listed in $arrDontListFiles) # EXCEPT php files will be shown and counted. # # # Ex. (3.) # # $arrDontListFilesExts = array(); # $arrListOnlyFilesExts = array("zip"); # # result : only zip files not listed in $arrDontListFiles # will be shown and counted. # # # Ex. (4.) # # $arrDontListFilesExts = array("txt"); # $arrListOnlyFilesExts = array("zip", "php", "txt"); # # result : only zip and php files not listed in $arrDontListFiles # will be shown and counted. Obviously this is a dumb thing to, # but it illustrates the precedence between consideration of # $arrDontListFilesExts and $arrListOnlyFilesExts #--------------------------------------------------- $arrDontListFilesExts = array(); $arrListOnlyFilesExts = array(); #--------------------------------------------------- # $intShowSubdirs <= set this to 0 and no directories will be shown. #--------------------------------------------------- $intShowSubdirs = 1; function getThisDirName($strUrl) { #--------------------------------------------------- # getThisDirName : Accepts the path to the directory either in the # form of $REQUEST_URI or a string value and pulls out the directory # name #--------------------------------------------------- $strAfterCutOne = substr($strUrl, 0, strrpos($strUrl, "/")); $strAfterCutTwo = substr($strAfterCutOne, strrpos($strAfterCutOne, "/") - strlen($strAfterCutOne) + 1); return $strAfterCutTwo; } #--------------------------------------------------- # isort and isortMultiD are 2 sorting functions used to add pseudo # alphabetical order to the list of directory names and file names #--------------------------------------------------- function isortMultiD($arrA,$arrB) { #--------------------------------------------------- # isortMultiD : This function basically is the same as issort, # except that it runs the comparison between the 2nd row in # each array, then the first. We'll be using it to sort the # filenames, where the j in $arrFiles[i][j] is the extension # (bmp, gif, jpg, etc) and the i is the name itself. #--------------------------------------------------- $intArrA0 = hexdec(ord(strtolower($arrA[0]))); $intArrB0 = hexdec(ord(strtolower($arrB[0]))); $intArrAn = hexdec(ord(strtolower($arrA[count ($arrA) - 1]))); $intArrBn = hexdec(ord(strtolower($arrB[count ($arrB) - 1]))); if($intArrAn == $intArrBn) { if($intArrA0 == $intArrB0) return 0; return ($intArrA0 < $intArrB0) ? -1: 1; } return ($intArrAn < $intArrBn) ? -1: 1; } function indexdirThisDir() { #--------------------------------------------------- # indexdirThisDir : This function scours through the current # directory (regardless of which directory u specify via the # getThisDirName call) and makes a list of directories and does the # same for files, first by their extensions and then by their names. # Remember that since it's only alphabetical on the first char php # and phtml or php3 and php files will be jumbled together, # as will html and htm (the same logic holds for file names). #--------------------------------------------------- global $arrBulletImgs; global $arrDontListFiles; global $arrDontListDirs; global $arrListOnlyFilesExts; global $arrDontListFilesExts; global $intShowSubdirs; $intNumHiddenDirs = 0; $intNumHiddenFiles = 0; $arrDirs = array(); $arrFiles = array(); $handleThisDir=opendir('.'); # get a handle on the current directory while (false!==($handleFileORdir = readdir($handleThisDir))) { if ($handleFileORdir != "." && $handleFileORdir != "..") { if(is_dir($handleFileORdir)== false) { $thisFileNoShow = 0; for ($i = 0; $i < count($arrDontListFiles); $i++) { if($handleFileORdir == $arrDontListFiles[$i]) { $thisFileNoShow = 1; //$intNumHiddenFiles++; break; } } if($thisFileNoShow == 0) { $arrFileNameAndExtension = explode(".", $handleFileORdir); array_push ($arrFiles, $arrFileNameAndExtension); } } else { $intThisDirNoShow = 0; for ($i = 0; $i < count($arrDontListDirs); $i++) { if($handleFileORdir == $arrDontListDirs[$i]) { $intThisDirNoShow = 1; break; } } if($intThisDirNoShow == 0) { array_push ($arrDirs, $handleFileORdir); } } } } closedir($handleThisDir); usort($arrDirs, 'isort'); usort($arrFiles, 'isortMultiD'); if ($intShowSubdirs != 0) { $strListingHTML .="\n".'
file | size (kb) | last modified |
'.$fileSizeInKb.' | '.$fileLastMod.' | |
'.$fileSizeInKb.' | '.$fileLastMod.' |