Backend Development 2 min read

PHP file_exists() Function: Description, Parameters, Return Value, and Usage Examples

The article explains PHP's file_exists() function, detailing its syntax, parameter requirements, return values, safe‑mode warning, and provides two practical code examples demonstrating how to check for the existence of files or directories.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP file_exists() Function: Description, Parameters, Return Value, and Usage Examples

Function Overview The file_exists() function checks whether a specified file or directory exists and returns TRUE if it does, otherwise FALSE .

Signature bool file_exists(string $filename)

Parameter $filename – the path to the file or directory. For Windows network shares use //computername/share/filename or \\computername\share\filename .

Return Value Returns TRUE when the file or directory exists; returns FALSE otherwise.

Warning If safe mode restricts access to the file, the function will return FALSE . In such cases, include can be used if the file resides in the directory specified by safe_mode_include_dir .

Example 1 – Conditional Check

Example 2 – Direct Call

backendphpfilesystemphp-functionsfile_exists
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.