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
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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.