How to check if File Exists in PHP ? (original) (raw)

Last Updated : 23 Jul, 2025

To check whether any file is existing or not then we can use the below-mentioned PHP function. To find the existence of the files, we use file_exists()function. This function is used to check whether a file or directory exists or not.

Syntax:

file_exists( $path )

Parameters: This function accept only one parameter $path. It specifies the path of the file or directory you want to check.Return Value: It returns True on success and false on failure.

Errors And Exception:

Example: Suppose there exists a file named "file1.php". Let's check the existence of files "file1.php".

PHP `

`

Output

File exist.