Jump to content

Help with alphabetizing folder contents


jay1318

Recommended Posts

First of all - wonderful site! Great people and very helpful for a newbie like me.

 

I have a simple php script that shows the files in a particular folder. Its working great but I need the results to return alphabetized. Much thanks in advance!

 

Here's my code...

 

<?PHP

 

$folder =

 

"/my/complete/path/";

 

 

 

$handle = opendir($folder);

 

# Making an array containing the files in the current directory:

while ($file = readdir($handle))

 

 

{

 

  $files[] = $file;

  }

 

  closedir($handle);

 

  #echo the files

  foreach ($files as $file) {

 

 

if($file == "." || $file == ".." || $file == "index.php" || $file == "thisfilename.php")

 

  continue;

  echo "<li><a href=$file>$file</a></li>"."<br />";

  }

 

  ?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/167301-help-with-alphabetizing-folder-contents/
Share on other sites

 

Maq already posted that Vineld, ha.  8)

 

That's it? Cool. But, can you possibly tell me where exactly to place it in the code or what it might replace?

 

Thanks again!

 

Take this example jay,

 

$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);

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.