Home > Article > Backend Development > Detailed explanation of the use of php file_exists() function
file_exists — Check whether the file or directory exists
Syntax
bool file_exists ( string $filename )
Check whether the file or directory exists.
Parameters filename The path of the file or directory.
Return value
Returns TRUE if the file or directory specified by filename exists, otherwise returns FALSE.
Note:If the file cannot be accessed due to safety mode restrictions, this function will return FALSE. However, it is possible to include using include if the file is in the directory specified by safe_mode_include_dir.
Note: Note: Because PHP's integer type is a signed integer type and many platforms use 32-bit integer types, for files above 2GB, some File System Functions may return unexpected results.
Example
1: Create a file.txt file in the F disk directory, and we determine that the file.txt file exists.
class test{ public function A($path){ if(!file_exists($path)){ echo "目录文件存在!"; }else{ echo "目录文件不存在!"; } } }$T=new test();$T->A("F:file.txt");
Output result:
Directory file exists!
The above is the detailed content of Detailed explanation of the use of php file_exists() function. For more information, please follow other related articles on the PHP Chinese website!