Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8423987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:52:11+00:00 2026-06-10T03:52:11+00:00

I have a website that contains a manual with many office precedents. When a

  • 0

I have a website that contains a manual with many office precedents. When a user uses the HTML upload script it uploads the precedent to a folder on the server. I use the following script to list out all the files in that specific folder.

<?php  //define the path as relative
  $dir = "./OFFICE PRECEDENTS/Business & Corporate Law"; 
  $webpath ="";  //using the opendir function  
  echo "<ol>";    
  // Open a known directory, and proceed to read its contents   
  if ($dh = opendir($dir)) {     
  while (($file = readdir($dh)) !== false) {   
  if (is_dir($dir.'/'.$file)){}      
  else if ($file == '.'){}      
  else if ($file == '..'){} 
  else if ($file == 'index.php'){}     
  else {      
  echo "<li><a href='https://manual.malicki-law.ca/$dir/$file'>$file</a></li>\n";      
  }    
  }       
  closedir($dh);     
  } 
  echo "</ol>";     
  ?>

How can I implement a system to alphabetically sort the list?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:52:12+00:00Added an answer on June 10, 2026 at 3:52 am

    For your specific case: If you use scandir() instead of readdir(), the default order is already in alphabetical order.

    http://php.net/manual/en/function.scandir.php

    The second parameter is:

    sorting_order
    By default, the sorted order is alphabetical in
    ascending order. If the optional sorting_order is set to
    SCANDIR_SORT_DESCENDING, then the sort order is alphabetical in
    descending order. If it is set to SCANDIR_SORT_NONE then the result is
    unsorted.

    So instead of:

     if ($dh = opendir($dir)) {     
       while (($file = readdir($dh)) !== false) {   
           // your code   
        }    
      }       
      closedir($dh);  
    

    Just use something like:

    if ($files = scandir($dir))
    {
        foreach ($files as $file) {
           // your code
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website that contains company profiles. These profiles have many pages within
I have a website that contains many different pages of products and each page
I have a website that contains pages with many small images. The images are
I have an IPAD compatible website that contains some staic html pages and some
I have a website that contains a list of articles. I want to include
I have a page on a website that contains a secure form inside an
I have a web site that contains an HTML form, in this form I
I have a website that uses the facebook, twitter, delicious share links. They contain
I have a website that is mainly based on JavaScript. It uses a REST
I have a website that contains links to other sites only. They link to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.