How to check if txt file exists in php

藏色散人
Release: 2023-03-08 17:46:01
Original
1932 people have browsed it

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.

How to check if txt file exists in php

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
Copy after login

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.
Copy after login

Note:

The check is done using the real UID/GID instead of the effective one.
Copy after login

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

Copy after login

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!

Related labels:
php
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!