Maverickb7 Posted February 21, 2007 Share Posted February 21, 2007 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 More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 What is parse($file)? You would have to load each file / folder into an array and sort the arrays. I usually seperate folders and put them at the top, then do the same with files below. Link to comment https://forums.phpfreaks.com/topic/39417-displaying-dirtory-items-in-order/#findComment-190172 Share on other sites More sharing options...
Maverickb7 Posted February 21, 2007 Author Share Posted February 21, 2007 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 https://forums.phpfreaks.com/topic/39417-displaying-dirtory-items-in-order/#findComment-190177 Share on other sites More sharing options...
Maverickb7 Posted February 21, 2007 Author Share Posted February 21, 2007 Any help would be appreciated. I was working on this a couple of months ago but its been pretty busy in my life so I've lost track of things. Maybe someone could help me out? Link to comment https://forums.phpfreaks.com/topic/39417-displaying-dirtory-items-in-order/#findComment-190198 Share on other sites More sharing options...
Maverickb7 Posted February 21, 2007 Author Share Posted February 21, 2007 please? Link to comment https://forums.phpfreaks.com/topic/39417-displaying-dirtory-items-in-order/#findComment-190592 Share on other sites More sharing options...
Maverickb7 Posted February 26, 2007 Author Share Posted February 26, 2007 anyone? Link to comment https://forums.phpfreaks.com/topic/39417-displaying-dirtory-items-in-order/#findComment-194038 Share on other sites More sharing options...
fert Posted February 26, 2007 Share Posted February 26, 2007 http://us2.php.net/manual/en/function.glob.php Link to comment https://forums.phpfreaks.com/topic/39417-displaying-dirtory-items-in-order/#findComment-194079 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.