Jump to content

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

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.