Emanuil Rusev Emanuil Rusev - 4 months ago 42
PHP Question

How to include only if file exists

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
but there is an issue with that approach - in case the file to be included exists, PHP will not output warnings if the parser find something wrong in the included file.

Answer
if(file_exists('file.php'))
    include 'file.php';

That should do what you want

Comments