Jump to content

[SOLVED] Putting a file directory in a specific order


jerel

Recommended Posts

Hello,

 

I have the code below, looking at the contents of the folder and listing the files, as links to themselves.

I would like to be able to control the way they are sorted. It seems very random.

 

I figured i could write all the file names to an array then have them write to a db, then pull those back from the db. So basically to avoid the extra scripting, is there some way to sort this?

 

thanks

 

??? code below

 

 

$dir = "../archives";

 

$dh = opendir($dir) or die ("could not open dir");

 

while ( !(($file = readdir($dh)) === false) )

{

 

if (($file != ".") && ($file != ".."))

{

//echo the link to the file here using the $file variable

echo "<a href='http://www.amimpact.com/archives/$file'>$file</a><br />";

 

}

 

}

Hello,

 

yes, thanks i also found the array_reverse() very helpful, here is the code if someone else would like to see this finished.

 

$dir = "../archives";

 

$dh = opendir($dir) or die ("could not open dir");

 

$n = "0";

while ( !(($file = readdir($dh)) === false) )

{

 

if (($file != ".") && ($file != ".."))

{

$n = $n+1;

//echo the link to the file here using the $file variable

 

$movies[$n] = "$file";

}

}

 

natsort($movies);

$newray = array_reverse($movies);

 

$array_count = count($newray);

 

for($i = 0; $i < $array_count; $i++) {

 

// echo whatever you want using $newray[$i] as your resorted array

echo "$newray[$i]";

 

//phpfreaks.com ROCKS THE HOUSE

 

}

 

?>

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.