Web Analytics Made Easy -
StatCounter Alphabetical Order - CodingForum


No announcement yet.

Alphabetical Order

  • Filter
  • Time
  • Show
Clear All
new posts

  • Alphabetical Order

    I have a script but i cant sort it alphabetically, i dunno how.

    It just lists the files randomly, even when uploaded.
    Is it because its in an input box? (thats so i can copy/paste fast).

    PHP Code:
    while(list($key,$value) = each($_FILES[images][name]))
    $filename $value;
    $add "img/$filename";
    //echo $_FILES[images][type][$key];
                     // echo "<br>";
    copy($_FILES[images][tmp_name][$key], $add);


    if (
    $handle opendir('/home/u2/jream/html/upload/img'))
        while (
    false !== ($file readdir($handle)))
            if (
    $file != "." && $file != "..")
    "<img src='http://jream.com/upload/arrow.gif'> <input type='text' value='http://www.jream.com/upload/img/$file' size='75'> <br />";

    www.jream.com/upload/ to see (pls dont upload anything unless u want to test it).

  • #2
    The readdir(...) function gets file names in the order they are in the file system. To get an alphabetical listing, you must either read the names into an array and sort them or use the glob(...) function (if your PHP version is high enough) to get them into an array (the default for glob is alphabetical.) Once you have the file names the way you want, you can loop over the array, using foreach(...), and form and output your echo statements.
    Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.