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 6390309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:30:39+00:00 2026-05-25T03:30:39+00:00

I am using a php scan directory script that will scan the contents of

  • 0

I am using a php scan directory script that will scan the contents of a directory and then populate the page with links to the directory contents.

<?php
$count = 0;
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
    if ($file != "." && $file != "..") {$count++;
        print("<a href=\"".$file."\">".$file."</a><br />\n");
    }
}
echo '<br /><br /><a href="..">Return</a>';
closedir($handle);
}
?

I am wondering how I can exclude certain files or file types like test.xml, durka.xslt or .html from showing up on the populated page. I have some code but not sure how to integrate it. Any help would be very appreciated…

?php
if ($handle = opendir(‘.’)) {
while (false !== ($file = readdir($handle)))
{
if ($file != “.” && $file != “..”
&& $file != “NOT-TO-BE-IN-1.php”
&& $file != “NOT-TO-BE-IN-2.html”
&& $file != “NOT-TO-BE-IN-3.jpg”
&& $file != “”
&& $file != “”
&& $file != “”
&& $file != “”
&& $file != “”

)
  • 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-05-25T03:30:40+00:00Added an answer on May 25, 2026 at 3:30 am
    <?php
    
      // These files will be ignored
      $excludedFiles = array (
        'excludeMe.file',
        'excludeMeAs.well'
      );
    
      // These file extensions will be ignored
      $excludedExtensions = array (
        'html',
        'htm',
        'php'
      );
    
      // Make sure we ignore . and ..
      $excludedFiles = array_merge($excludedFiles,array('.','..')); 
    
      // Convert to lower case so we are not case-sensitive
      for ($i = 0; isset($excludedFiles[$i]); $i++) $excludedFiles[$i] = strtolower(ltrim($excludedFiles[$i],'.'));
      for ($i = 0; isset($excludedExtensions[$i]); $i++) $excludedExtensions[$i] = strtolower($excludedExtensions[$i]);
    
      // Loop through directory
      $count = 0;
      if ($handle = opendir('.')) {
        while (false !== ($file = readdir($handle))) {
          $extn = explode('.',$file);
          $extn = array_pop($extn);
          // Only echo links for files that don't match our rules
          if (!in_array(strtolower($file),$excludedFiles) && !in_array(strtolower($extn),$excludedExtensions)) {
            $count++;
            print("<a href=\"".$file."\">".$file."</a><br />\n");
          }
        }
        echo '<br /><br /><a href="..">Return</a>';
        closedir($handle);
      }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using PHP, I scan a directory and list all of the .xml files. Each
Using PHP, it's possible to read off the contents of a file using fopen
Using Php I would like to extract the current Url of a page including
I am using PHP and I need to script something like below: I have
I am using the following code in WINDOWS OS and PHP script, in which
I have some tasks on a site in php using nginx that I'm trying
I'm using the following code to scan a folder for images: <?php $dir =
Using PHP.. I have a small app that I built that currently uses a
Possible Duplicate: how to delete a folder with contents using PHP hi, is it
I'm trying to learn Symfony that requires using php in the command line /

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.