Arrange Files By....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Arrange Files By....

Post by Zeceer »

I got this simple script that loops thru a folder that includes the files in the folder:
<?php

$dirname = "produkter";
$dh = opendir( $dirname );

while( $file = readdir( $dh ) )
{
if(is_file("$dirname/$file"))
include("$dirname/$file");
}

?>
In the folder the files are arranged by name. But when the script includes the files, it looks like there included by the date. The oldest on top and so on. Is there any way to arrange the files another way? After name would be great.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

viewtopic.php?t=1241 has a quite similar topic
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Post by Zeceer »

The thing here is that i'm gonna arrange the files by name, not last updatet. Don't have any ideas on have this can be done :oops:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

  • almost the same way
  • open a dir-descriptor
  • append all filenames to an array
  • sort that array
it's even simpler since you do not need an user-defined compare-function, sort() will do
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Post by Zeceer »

Get it. Thanx :D
Post Reply