How to query whether a txt file exists in php: first create a PHP sample file; then define the path of the TXT file that needs to be queried; and finally judge by "if(file_exists($filename)) {...}" txt file exists.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
file_exists - Check whether the file or directory exists
Description
file_exists ( string $filename ) : bool
Check whether the file or directory exists.
Parameters
filename
The path to the file or directory.
In Windows, use //computername/share/filename or \\computername\share\filename to check shared files on the network.
Return value
Returns true if the file or directory specified by filename exists, otherwise returns false.
Note:
This function will return false for symlinks pointing to non-existing files.
Note:
The check is done using the real UID/GID instead of the effective one.
Note: Because PHP’s integer type is a signed integer and many platforms use 32-bit integers, for files above 2GB , some file system functions may return unexpected results.
[Recommended study: "PHP Video Tutorial"]
Example
Example #1 Test whether a file exists
<?php $filename = '/path/to/foo.txt'; if (file_exists($filename)) { echo "The file $filename exists"; } else { echo "The file $filename does not exist"; } ?>
Error/Exception
Throw E_WARNING warning on failure.
Comments
Note: The result of this function will be cached. See clearstatcache() for more details.
Tips
Since PHP 5.0.0, this function is also used in some URL wrappers. See Supported Protocols and Wrapper Protocols for a list of wrappers that support the functionality of the stat() family of functions.
The above is the detailed content of How to check if txt file exists in php. For more information, please follow other related articles on the PHP Chinese website!