Check if a path will fail due to open_basedir

1.1k Views Asked by At

Is it possible to check this before failing ?

if (is_in_open_basedir($path)) {
}
3

There are 3 best solutions below

1
On

This is not a php standard function. To handle exceptions you can use:

try {

}
catch( $e ) {

}

Check this: PHP Exceptions

0
On

You can use ini_get to get the current value of open_basedir to check against the other value.

0
On

I know this does not answer the question exactly, but maybe the motivation behind it:

If you do not need to check before the call and just want to avoid warnings, on functions that access other dirs, another approach would be to use the @ operator and check error_get_last

error_clear_last();
$isDir = @is_dir('/');
if (error_get_last() !== null) {
   $isDir = 'cannot-detect';
}