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.
To check if a file exists, you pass the file path to the exists() function from the os. path standard library. If the file exists, the exists() function returns True . Otherwise, it returns False .
just do @rm -f myfile. Because of the "-f" flag, "rm" will exit with 0 regardless of whether the file exists or not. Or, -rm myfile the lead dash telling make to ignore any error.
In Python, you can check whether certain files or directories exist using the isfile() and isdir() methods, respectively. However, if you use isfile() to check if a certain directory exists, the method will return False. Likewise, if you use if isdir() to check whether a certain file exists, the method returns False.
Use ifile. open(): ifile. open() is mainly used to check if a file exists in the specific directory or not.
if(file_exists('file.php')) include 'file.php';
That should do what you want
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With