Jump to content

Sorting Values Retrieved From Directory


billhobbs

Recommended Posts

I have a script that retrieves the names of photos in a photo directory. I want to sort them by the names, but my sorting isn't working. Everything seems to work except the order is wrong. My code is below. Any help is appreciated.

$path = "../arrangements";
if(isset($_POST['file']) && is_array($_POST['file']))
{
    
    foreach($_POST['file'] as $file)
    {    
        unlink($path . "/" . $file) or die("Failed to <strong class='highlight'>delete</strong> file");
    }
}


$path = "../arrangements";
$dir_handle = @opendir($path) or die("Unable to open folder");
while (false !== ($file = readdir($dir_handle))) 
{
sort($file);
if($file == ".")
continue;
if($file == "..")
continue;
echo "<img src='../arrangements/$file' alt='$file'><br />";
    $filename = substr($file, 0, strrpos($file, "."));
echo $filename;
}

Edited by billhobbs
Link to comment
Share on other sites

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.