Apache HTACCESS directory/wrong php code? -


i run apache server on network movies. discovered power of .htaccess , decided i'd try use make directories nice instead of default index. problem use basic php script gets directory, , not inside movie directories want. reason i'm doing don't have copy/paste index file every single of 540 folders. i'm not sure if there's i'm doing wrong or different php use. appreciated.

this .htaccess

# disable directory views options +indexes  # strong htaccess protection <files ~ "^.*\.([hh][tt][aa])"> order allow,deny deny </files>  # directory customization <ifmodule mod_autoindex.c>  </ifmodule>  # set index options indexoptions ignorecase fancyindexing foldersfirst namewidth=70    descriptionwidth=* versionsort suppresshtmlpreamble iconwidth=40 suppressdescription suppresslastmodified suppresssize htmltable   # specify header file headername /header.php  # specify footer file readmename /footer.html  # ignore these files indexignore header.html index.php *.nfo *.txt *.srt footer.html favicon.ico .htaccess .ftpquota .ds_store icons *.log *,v *,t .??* *~ *# thumbs.db  directoryindex index.html index.php 

and php:

<?php    // open directory    $mydirectory = opendir(".");    // each entry   while($entryname = readdir($mydirectory)) {           $dirarray[] = $entryname;   }    // close directory   closedir($mydirectory);    //      count elements in array   $indexcount     = count($dirarray);    // sort 'em   sort($dirarray);    // print 'em    print("<table border=1 cellpadding=10 cellspacing=0 class='main'>");   print ("<td><b>$indexcount movies</b></td>");    //print("<tr><th>filename</th></tr>\n");    // loop through array of files , print them   for($index=0; $index < $indexcount; $index++) {           if (substr("$dirarray[$index]", 0, 1) != "."){// don't list hidden files                   print("<tr><td width='50%'><a href=\"$dirarray[$index]\">$dirarray[$index]</a></td>");                   print("</tr>\n");           }           }   print("</table>\n");   ?> 

this recoursive directory reader class:

class directoryreader {        public static function readfolderrecursive($folder, &$res) {           if(substr($folder,-1) == "/") {               $folder = substr($folder,0,-1);           }           $data = self::readfolder($folder);           foreach($data['files'] $k => $f) {               $res[] = array('type'=>'file','path'=>$folder."/".$f, 'filename'=>$f);           }           foreach($data['folder'] $k => $f) {               $tmp = $folder."/".$f;               $res[] = array('type'=>'folder','path'=>$folder."/".$f);               self::readfolderrecursive($tmp, $res);           }       }        public static function readfolder($folder) {           $files = array();           $folders = array();            if(is_dir($folder) ) {               if(substr($folder,-1) == "/") {                   $folder = substr($folder,0,-1);               }               $handle = opendir($folder);               while ($file = readdir ($handle)) {                   if($file != "." && $file != "..") {                       if(is_dir($folder."/".$file)) {                           $folders[] = $file;                       } else {                           $files[]= $file;                       }                   }               }               closedir($handle);           }           return array("folder" => $folders, "files" => $files);       }  }  $data = array(); directoryreader::readfolderrecursive(".",$data);  echo "<pre>"; print_r($data); echo "</pre>"; 

it reads subfolder , files of given folder array. should able format resulting $data array yourself.

so able produce single page can see contents of subfolders. don't need reload php-file if want open directory. can resolve pure javascript.

an example result this:

array (     [0] => array         (             [type] => file             [path] => ./test.php             [filename] => test.php         )      [1] => array         (             [type] => folder             [path] => ./example_folder_2         )      [2] => array         (             [type] => file             [path] => ./example_folder_2/file3.txt             [filename] => file3.txt         )      [3] => array         (             [type] => folder             [path] => ./example_folder_1         )      [4] => array         (             [type] => file             [path] => ./example_folder_1/file1.txt             [filename] => file1.txt         )      [5] => array         (             [type] => folder             [path] => ./example_folder_1/example_subfolder         )      [6] => array         (             [type] => file             [path] => ./example_folder_1/example_subfolder/file2.txt             [filename] => file2.txt         )  ) 

Comments