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

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

怪我咯
Release: 2023-03-13 13:54:02
Original
1967 people have browsed it

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 不存在";
}
?>
Copy after login

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

Example two

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template