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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:20:45+00:00 2026-06-13T17:20:45+00:00

Possible Duplicate: Check whether a Directory Exists in PHP I am trying scandir() to

  • 0

Possible Duplicate:
Check whether a Directory Exists in PHP

I am trying scandir() to check contents of directories and sending path parameter using javascript and trying to load the contents in #container div:

$("#container").load("fetch_images.php?path="+pathvariable);

in fetch_images.php I am trying scandir($_GET['pathvariable']) to scan the elements of given directory. My problem is if proper path is not supplied using $_GET[‘pathvariable’] the page is showing some warning and error.

trying to scan like $files_dir_results = scandir($path); and using foreach() to display all results of the array.

I don’t want to show any kind of warning or error on output page. I know I can disable PHP warning but I will prefer any better option.

I don’t know how to check if scandir() is returing any error or warning. thanks.

  • 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-13T17:20:46+00:00Added an answer on June 13, 2026 at 5:20 pm

    You should first check if the path is valid with is_dir then scan it

    $images = array();
    $valid_images = array('jpg','png','gif');
    if(is_dir($_GET['path'])){
      foreach(scandir($_GET['path']) as $file){
        $ext = pathinfo($file, PATHINFO_EXTENSION);
        if(in_array($ext, $valid_images)){
          array_push($images, $file);
        }   
     }
    }
    
    echo json_encode($images);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Check synchronously if file/directory exists in Node.js For example, i have a
Possible Duplicate: How to check if an email address exists without sending an email?
Possible Duplicate: Check whether $_POST-value is empty I am using this code to validate
Possible Duplicate: check whether internet connection is available with C# I just want to
Possible Duplicate: Check if a variable is empty Simple PHP question: I have this
Possible Duplicate: How to check file types of uploaded files in PHP? I have
Possible Duplicate: How can you check for a #hash in a URL using JavaScript?
Possible Duplicate: How can you check for a #hash in a URL using JavaScript?
Possible Duplicate: How to check whether 2 DirectoryInfo objects are pointing to the same
Possible Duplicate: How can I check whether a option already exist in select by

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.