PHP is_file() Function: Description, Parameters, Return Values, and Usage Examples

The article explains PHP's is_file() function, detailing its signature, parameter description, return values, important notes on large files and caching, and provides two practical code examples demonstrating how to check for regular files.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP is_file() Function: Description, Parameters, Return Values, and Usage Examples

is_file() checks whether a given filename refers to a regular file.

Signature: bool is_file(string $filename) Parameter: $filename – the path to the file.

Return value: Returns TRUE if the file exists and is a regular file; otherwise returns FALSE.

Note: On 32‑bit systems, files larger than 2 GB may produce unexpected results; use clearstatcache() to clear cached results.

Example 1:

<?php
var_dump(is_file('a_file.txt'));
var_dump(is_file('/usr/bin/'));
?>

Outputs bool(true) for an existing regular file and bool(false) for a directory.

Example 2:

<?php
$file = "test.txt";
if (is_file($file)) {
    echo "$file is a regular file";
} else {
    echo "$file is not a regular file";
}
?>
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendPHPFilesystemfile-handlingis_file
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

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.