Loading ...
Sorry, an error occurred while loading the content.

277Re: reg:files

Expand Messages
  • Mani Shankar Dwivedi
    Nov 26, 2006
    • 0 Attachment
      --- In bang-phpug@yahoogroups.com, "skumar_sss" <skumar_sss@...> wrote:
      >
      > hello
      >
      > any one can say about how to seperate the files and folder in a
      > particular directory.
      >

      <html>
      <head>
      <title>Recursive Directory File Lister</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      <style>
      <!--
      a{text-decoration:none}
      //-->
      </style>
      </head>

      <body>
      <?php
      /*
      Recursive directory file lister

      Scans through the current directory, and lists all the files and
      folders in it
      it then goes onto the next directory and lists all the files and
      folders in that
      etc etc

      File Vesion 1.3

      Changes:
      1.0 -> 1.2
      Auto finds the root path of the directory
      Auto finds the www. path of the directory
      added the view link and file numbers
      1.2 - 1.3
      Complete Rewrite
      Added File Sizes
      Made into a mambo component
      Displays In Tree Format
      Folders Displayed In Bold
      Added Total File Sizes and Number Of Folders

      */

      function direcho($path) {
      global $filetotal, $fullsize, $totaldirs;
      if ($dir = opendir($path)) {
      while (false !== ($file = readdir($dir))) {
      if (is_dir($path."/".$file)) { // if it's a dir,
      check it's contents too
      if ($file != '.' && $file != '..') { // but don't go
      recursive on '.' and '..'
      echo '<li><img src="folder.jpg"><a href = ' . $path."/".$file .
      '><b>' . $file . '</b></a></li><ul>';
      direcho($path."/".$file);
      echo '</ul>';
      $totaldirs++;
      }
      }
      else { //if it's not a dir, just output.
      $tab = "      ";
      $filesize = $tab . '(' . filesize ($path.'/'.$file) . ' bytes)';
      echo '<li>' . $file . $filesize . '</li>';
      $fullsize = $fullsize + filesize ($path.'/'.$file);
      $filetotal++;
      }
      }
      closedir($dir);
      }
      }

      direcho('.');

      $fullsize = round($fullsize / 1024 / 1024, 2);







      echo "<font size=\"2\" face=\"Arial, Helvetica, sans-serif\">
      <b>Total files</b> - $filetotal files<br>
      <b>Total dirs</b> - $totaldirs directories<br>
      <b>Total size</b> - $fullsize MB<br>";
      ?>
      </body>
      </html>

      this code list the current folder's file list and sub-folder list
      folder shows as an icon "folder.jpg" u can make your own image.
      this programs also returns the count/size of files & folder
    • Show all 3 messages in this topic