Jump to content

Displaying Dirtory Items in Order?


Maverickb7

Recommended Posts

Hello--

I'm trying to code a simple script that will allow me to list all files within a directory in order by letter. I'm using the below code and was wondering if anyone knew how I could modify it to do this? Thanks in advance!!

 

           $dirpath = "./files";

    $dh = opendir($dirpath);
        while (false !== ($file = readdir($dh))) {
                       if (!is_dir("$dirpath/$file")) {
       $fileend = substr($file, -;
             $fileend = strtolower($fileend);

if ( $fileend == ".rar" ) {            

if (isset($file))  {
        Parse($file);
      }
                else {
                           echo "No file name has been specified. Please Specify One.";
                }
               }
}
    }
     closedir($dh);

 

does anyone know what I would have to add to have this done?

Link to comment
https://forums.phpfreaks.com/topic/39417-displaying-dirtory-items-in-order/
Share on other sites

here is the entire code. if anyone could help me that would be create. i've been trying to get this to work for the last couple of weeks with no luck. :(

 

<html>
<head>
<title>The Spot</title>
<link rel="stylesheet" type="text/css" href="../spot/css.php?theme=2">
</head>
<body>
<?
// End of config area
error_reporting  (0);

function pathurlencode($uri) {
        $uri = urlencode($uri);
        $uri = str_replace('%3A', ':', $uri);
        $uri = str_replace('%2F', '/', $uri);
        $uri = str_replace('%26', '&', $uri);
        $uri = str_replace('%40', '@', $uri);
        $uri = str_replace('%3A', ':', $uri);
        $uri = str_replace('%3F', '?', $uri);
        $uri = str_replace('%3D', '=', $uri);
        $uri = str_replace('%5B', '[', $uri);
        $uri = str_replace('%5D', ']', $uri);
        return $uri;
    }
    // From php.net
    function getfilesize($bytes) {
   if ($bytes >= 1099511627776) {
       $return = round($bytes / 1024 / 1024 / 1024 / 1024, 2);
       $suffix = "TB";
   } elseif ($bytes >= 1073741824) {
       $return = round($bytes / 1024 / 1024 / 1024, 2);
       $suffix = "GB";
   } elseif ($bytes >= 1048576) {
       $return = round($bytes / 1024 / 1024, 2);
       $suffix = "MB";
   } elseif ($bytes >= 1024) {
       $return = round($bytes / 1024, 2);
       $suffix = "KB";
   } else {
       $return = $bytes;
       $suffix = "Byte";
   }
   if ($return == 1) {
       $return .= " " . $suffix;
   } else {
       $return .= " " . $suffix;
   }
   return $return;
}

function Parse($filename) {
        require_once("BDecode.php") ;
        require_once("BEncode.php") ;
            global $seedsandpeers;
       $torrent = explode(".", $filename);
    $fileend = end($torrent);
    $fileend = strtolower($fileend);
if ( $fileend == "rar" ) {
$stream = @file_get_contents("./files/$filename");
if ($stream == FALSE) {
echo "$filename cannot be opened" ;

}
if(!isset($stream)){
echo "Error in Opening file." ;
    }else{
            $array = BDecode($stream);
if ($array === FALSE){
echo "Error in file. Not valid BEncoded Data." ;

}else{
if(array_key_exists("info", $array) === FALSE){
echo "Error in file. Not a valid files file." ;

}else{

echo "<tr><td><span class=\"smalltext\">".$filename."</span></td>" ;

       $infovariable = $array["info"];
       


if (isset($infovariable["files"]))  {

      foreach ($infovariable["files"] as $file)
                        {

   $multitorrentsize = $file['length'];
   $filessize += $file['length'];
     
                           }
echo "<td align=\"right\"><span class=\"smalltext\">";
                                echo getfilesize($filessize);
echo "</span></td></tr>";
        }
        else {
        // Calculates File size in KB and rounds to 2 decimal places
        echo "<td align=\"right\"><span class=\"smalltext\">";
       $filessize = $infovariable['length'];
       echo getfilesize($filessize);
echo "</span></td></tr>";
        }
        }
}
}
}


}




echo "<center><table cellspacing=\"0\" cellpadding=\"2\" border=\"1\" width=\"500\">";
echo "<tr><td><span class=\"smalltext\"><b>Title:</b></span></fd><td align=\"center\"><span class=\"smalltext\"><b>Size</b></span></td></tr>";  


           $dirpath = "./files";

    $dh = opendir($dirpath);
        while (false !== ($file = readdir($dh))) {
                       if (!is_dir("$dirpath/$file")) {
       $fileend = substr($file, -3);
             $fileend = strtolower($fileend);

if ( $fileend == ".rar" ) {

if (isset($file))  {
        Parse($file);
      }
                else {
                           echo "No file name has been specified. Please Specify One.";
                }
               }
}
    }
     closedir($dh);

echo "</table></center>";





?>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.