I need an include
function / statement that will include a file only if it exists. Is there one in PHP?
You might suggest using @include
bu
Try using file_exists()
if(file_exists($file)){
include $file;
}
Based on @Select0r's answer, I ended up using
if (file_exists(stream_resolve_include_path($file)))
include($file);
This solution works even if you write this code in a file that has been included itself from a file in another directory.
I think you have to use file_exists
, because if there was such an include, it would have been listed here: http://php.net/manual/en/function.include.php
How about using file_exists
before the include
?