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.
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";
}
?>Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
