Home  >  Article  >  Backend Development  >  Detailed explanation of the use of file_exists() function in php

Detailed explanation of the use of file_exists() function in php

怪我咯
怪我咯Original
2017-07-11 10:42:331851browse

file_exists — Check whether the file or directory exists

Description:
bool file_exists ( string $filename )

Returns TRUE if the file or directory specified by filename exists, otherwise returns FALSE.

Example

Example one

<?php
$filename = &#39;/www/aa/to/foo.txt&#39;;
if (file_exists($filename)) {
echo "文件$filename exists";
} else {
echo "文件$filename 不存在";
}
?>

The output result is:
File/www/aa/to/foo.txt already exists

Example two

<?php
echo file_exists("test.txt");
?>

Use file_exists directly to return true or false.

The above is the detailed content of Detailed explanation of the use of file_exists() function in php. For more information, please follow other related articles on the PHP Chinese website!

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