How to include only if file exists

前端 未结 10 840
深忆病人
深忆病人 2020-12-28 12:24

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

10条回答
  •  既然无缘
    2020-12-28 12:52

    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.

提交回复
热议问题