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

  • SEARCH
  • Home
  • 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 9279641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:41:02+00:00 2026-06-18T17:41:02+00:00

Basically I have a php script that lists all the files in a directory

  • 0

Basically I have a php script that lists all the files in a directory and creates links to them. However it seems to order the files in a very arbitrary fashion (not according alphabetically/by date/ by size etc…). What way does php order the files? Is there any way to change this?

 <?php
    $orig = "/var/www/phplist";
    if ($dir = opendir($orig)) {
        echo "from: $orig";
        echo "<br><br>";

        while ($file = readdir($dir)) {
        $ok = "true";
        $filename = $file;
        if ($file == "."){
        $ok = "false";
        }
        else if ($file == ".."){
        $ok = "false";
        }
        if ($ok == "true"){
          echo "<a href= '/phplist/$file'>$filename</a>";
        echo "<br>";
        }
        }

        closedir($dir);
    }
    ?> 
  • 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-18T17:41:04+00:00Added an answer on June 18, 2026 at 5:41 pm

    The documentation for this function explains what you’re looking for:

    Returns the name of the next entry in the directory. The entries are
    returned in the order in which they are stored by the filesystem.

    And depending on the filesystem, the files might retain the order in which they were created (FAT); might be sorted alphabetically (NTFS); might be sorted according to their position in a hash table (ext4); or various other ways.

    If you need files in a specific order look at scandir which takes a parameter that specifies the sort order.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So basically I have a PHP script that takes all the images from the
I have a print.php script that basically fetches data from MySQL and creates a
Basically I have a php script located on a sever that generates a JSON
I have had lots of help with creating a PHP script that basically grabs
I have a php script that transfers a bunch of files between servers with
I have a very large php maintenance script (basically it recreates thumbnails for an
Basically I have a single page on my site that I want any php
Basically, we have an ASP website right now that I'm converting to PHP. We're
I have a PHP script that reads a file and outputs it to the
<a href=PHP/LogOut.php id=LogOut>Log Out</a> the link a#LogOut calls a PHP script that ends all

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.