Home  >  Article  >  Backend Development  >  file_exists - Check if a file or directory exists_PHP Tutorial

file_exists - Check if a file or directory exists_PHP Tutorial

WBOY
WBOYOriginal
2016-07-20 11:01:041421browse

file_exists - Check if a file or directory exists ​

file_exists
(PHP 4, PHP 5)

file_exists - Check if a file or directory exists

Description
boolean file_exists (string $filename)
Check if the file or directory exists.

Parameters

File name
The path to the file or directory.

In Windows, use //computername/share/filename or computernameshare-filename to check for files on a network share.


Return value
Returns TRUE if the file or directory specified by filename exists; FALSE otherwise.

NOTE: This function will return FALSE for symlinks pointing to non-existent files.


Warning
This function returns FALSE for files that cannot enter safe mode due to restrictions. But these files can also be included if they are located in safe_mode_include_dir.

NOTE: The check is using real UID/GID which is not valid.


Example

Example #1 Test if file exists

$filename = '/path/to/foo.txt';

if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445479.htmlTechArticlefile_exists - Check whether a file or directory exists file_exists (PHP 4, PHP 5) file_exists - Check a file or directory boolean file_exists describing whether it exists (string $filename)...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn