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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:53:06+00:00 2026-06-08T17:53:06+00:00

How may i able to retrieve different file extensions in a certain directory. Let

  • 0

How may i able to retrieve different file extensions in a certain directory. Let say i have a folder named “downloads/”, where inside that folder are different types of files like PDFs, JPEGs, DOC files etc. So in my PHP code i wanted those files be retrieved and listed with there file names and file extensions. Example: Inside “downloads/” folder are different files

downloads/

 - My Poem.doc
 - My Photographs.jpg
 - My Research.pdf

So i wanted to view those files where i can get there file names, file extensions, and file directories. So in view will be something like this

Title: My Poem
Type: Document
Link: [url here] 

Title: My Photographs
Type: Image
Link: [url here] 

Title: My Research
Type: PDF
Link: [url here] 

Anyone knows how to do it in php? Thanks a lot!

  • 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-08T17:53:09+00:00Added an answer on June 8, 2026 at 5:53 pm

    It’s pretty simple. To be honest i don’t know why didn’t you searched on a php.net. They got whole lots of examples for this. Check it in here: click

    Example:

    <?php
    
      function process_dir($dir,$recursive = FALSE) {
        if (is_dir($dir)) {
          for ($list = array(),$handle = opendir($dir); (FALSE !== ($file = readdir($handle)));) {
            if (($file != '.' && $file != '..') && (file_exists($path = $dir.'/'.$file))) {
              if (is_dir($path) && ($recursive)) {
                $list = array_merge($list, process_dir($path, TRUE));
              } else {
                $entry = array('filename' => $file, 'dirpath' => $dir);
    
     //---------------------------------------------------------//
     //                     - SECTION 1 -                       //
     //          Actions to be performed on ALL ITEMS           //
     //-----------------    Begin Editable    ------------------//
    
      $entry['modtime'] = filemtime($path);
    
     //-----------------     End Editable     ------------------//
                do if (!is_dir($path)) {
     //---------------------------------------------------------//
     //                     - SECTION 2 -                       //
     //         Actions to be performed on FILES ONLY           //
     //-----------------    Begin Editable    ------------------//
    
      $entry['size'] = filesize($path);
      if (strstr(pathinfo($path,PATHINFO_BASENAME),'log')) {
        if (!$entry['handle'] = fopen($path,r)) $entry['handle'] = "FAIL";
      }
    
     //-----------------     End Editable     ------------------//
                  break;
                } else {
     //---------------------------------------------------------//
     //                     - SECTION 3 -                       //
     //       Actions to be performed on DIRECTORIES ONLY       //
     //-----------------    Begin Editable    ------------------//
    
     //-----------------     End Editable     ------------------//
                  break;
                } while (FALSE);
                $list[] = $entry;
              }
            }
          }
          closedir($handle);
          return $list;
        } else return FALSE;
      }
    
      $result = process_dir('C:/webserver/Apache2/httpdocs/processdir',TRUE);
    
     // Output each opened file and then close
      foreach ($result as $file) {
        if (is_resource($file['handle'])) {
            echo "\n\nFILE (" . $file['dirpath'].'/'.$file['filename'] . "):\n\n" . fread($file['handle'], filesize($file['dirpath'].'/'.$file['filename']));
            fclose($file['handle']);
        }
      }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem that I thought someone may be able to help me
I wonder whether someone may be able to help me please. Firstly apologies as
I wonder whether someone may be able to help me please. I'm using the
I wonder whether someone may be able to help me please Firstly, my apologies
I wonder whether someone may be able to help me please. Firstly, this is
I wonder whether someone may be able to help me please. Firstly, my apologies
I wonder whether someone may be able to help me please. I feel I
I wonder whether someone may be able to help me please. Firstly my apologies.
I wonder whether someone may be able to help me please. I'm using Aurigma
That title may need some work. Perhaps after reading this, you may be able

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.