Backend Development 4 min read

How to Use PHP is_file() to Check File Existence and Type

This article explains the PHP is_file() function, covering its syntax, parameters, return values, and provides clear code examples for checking whether a path exists, is a regular file, and how to differentiate files from directories using is_dir().

php中文网 Courses
php中文网 Courses
php中文网 Courses
How to Use PHP is_file() to Check File Existence and Type

In PHP programming, the is_file() function is a useful tool for determining whether a given path exists and is a regular file. This article introduces its syntax, parameters, return values, and provides several code examples.

Syntax:

bool is_file ( string $filename )

The function accepts a single argument $filename representing the path to check and returns true if the path points to an existing regular file, otherwise false .

Example 1 – checking a file’s existence:

This script defines $file , calls is_file() , and outputs a message indicating whether the file exists.

Beyond existence, is_file() also distinguishes regular files from directories or special files; it returns false for those.

Example 2 – verifying a path is a regular file:

Here $path is checked; the script prints a message based on whether the path is a regular file.

Note: to test for directories, use is_dir() instead of is_file() .

In summary, is_file() is a practical PHP function for file‑system checks, and understanding its usage helps developers write more robust backend code.

Java learning material download

C language learning material download

Frontend learning material download

C++ learning material download

PHP learning material download

backendPHPfilesystemfile handlingis_file
php中文网 Courses
Written by

php中文网 Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.