PHP Scandir() error handling

I am using scandir() function to get the file list of a network path. I am using an path which I dont have access to. I am trying to use it in if condition,

     if(scandir("path") == false)
     {
     //code
     }
     else
     {
     //code
     }

This works but the Scandir error is also displayed.
The system cannot find the path specified. (code: 3).
failed to open dir: No such file or directory.

I Basically Dont want the scandir error to display.

Problem Solved. Using is_dir instead of scandir.

For future reference try setting the following:

ini_set( 'display_errors', false);

Errors should then go to the error log file and not show on screen.

This should also be the default online setting.

Ok Thanks. Another question, is_dir() will check if the specified path is a directory or not.
What I am trying to do is, if the directory does not exist the user should get the message like “Directory Missing” but if the path is not Accessible then the user should get “Access Denied”.
Is there any function to check if there is access to the folder?

1 Like

@John_Betong
Spamming the log file with unnecessary errors is scarcely better than displaying them on screen.
Although this your recommendation is proper by itself, it is irrelevant to the question asked, where the error itself, not the error message have to be treated properly.

@akshay_khairmode
define “Not accessible”. Not accessible by whom? Not accessible for what?

1 Like

It is a network path so when I put \ip\share into RUN then I get a message Access Denied as my Windows Login does not have access for it,but if a user logs in with another Windows login who has the access for that network share it will work.

That’s quite a question. I’ve no idea whether it’s even possible at all.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.