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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:36:05+00:00 2026-06-10T20:36:05+00:00

I have a system that stores user comments in its own individual json file.

  • 0

I have a system that stores user comments in its own individual json file. I use scandir(); on the directory which gets all files and folders, but how do I limit it to json files, I don’t want other files such as “.” and “..” in the array because I need an accurate count.

I checked out the info on php.net but couldn’t figure it out, perhaps you know of a resource you can point me toward, or which function to use.

  • 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-10T20:36:07+00:00Added an answer on June 10, 2026 at 8:36 pm

    There are no stream context parameters that will help you filter out the types of files.

    Assuming that your JSON files are saved with the .json extension, you just have to filter out the array based on the file extensions.

    You can use readdir() to build a list of files, or simply loop over the results you get from scandir and create a new array from that.

    Here is an example using readdir:

    $files = array();
    $dh = opendir($path);
    while (($file = readdir($dh) !== false) {
        if (pathinfo($path . '/' . $file, PATHINFO_EXTENSION) !== 'json') continue;
        $files[] = $path . '/' . $file;
    }
    
    closedir($dh);
    
    // $files now has an array of json files
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a system that stores vectors and allows a user to find the
I have a table that stores all data that a user answers. I am
I am using SQL Server 2008. I have a table (TBL_FILE) that stores user
I have a sql database that stores some documents. A user can sign into
I have 2 tables: 1) game_follower (stores which user is following which game): ___________________________
I have a notification system in which there are various types comments, product_added etc.
We have system here that uses Java JNI to call a function in a
I have a system that takes dynamic data, puts it in HTML for layout
I have big system that make my system crash hard. When I boot up,
I have a system that runs like this: main.exe runs sub.exe runs sub2.exe and

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.