-2

Not skilled with PHP at all. I used old code from another site (that I did not write) to create a CMS for a client. Problem is, the directory results here are not returned alphabetically. I have read that scandir will do that, whereas readdir will not. I also know that an array or any number of sort functions would also work... I just don't know how to do it :) Any help would be much appreciated.

<select name="image1[<?print($i);?>]">
<option value="none.gif">no photo available</option>
<?
$handle = opendir($art_image);
while ($file = readdir($handle)) {
    if ($file !="." && $file !="..") {
        option($file,$row["image1"]);
    }
}
?>
</select>

3 Answers3

1
<select name="image1[<?print($i);?>]">
<option value="none.gif">no photo available</option>
<?

while ($item = scandir($art_image, SCANDIR_SORT_DESCENDING)) 
{
    if ('.' !== $item[0]) // skip . .. and hidden files all in one swoop
    {
        option($item, $row['image1']);
    }
}

?>
</select>
kittycat
  • 14,983
  • 9
  • 55
  • 80
0
while ($file = scandir($art_image)) {
...

That should do it for you. No handle required with scandir.

JLZenor
  • 1,460
  • 2
  • 14
  • 23
0

You can simply use scandir and then sort the array() with sort()

Tom
  • 3
  • 2
  • Welcome to SO! Note that is customary to leave a example code when providing a answer, also, for future reference, try to provide a more complete answer, since many users flag/downvote short answers. – Hristo Valkanov Jul 17 '14 at 11:57