PHP is_dir() Function: Determine if a Path is a Directory
This article explains the PHP is_dir() function, describing its purpose to check whether a given filename refers to an existing directory, detailing its parameter, return values, and providing example code snippets demonstrating true and false outcomes for various path inputs.
The is_dir() function in PHP returns a boolean indicating whether the supplied filename corresponds to an existing directory.
Signature: bool is_dir(string $filename) Description: It checks the given path; if the filename exists and is a directory, it returns TRUE, otherwise FALSE. Relative paths are resolved against the current working directory.
Parameter: $filename – the path to test; can be absolute or relative.
Return value: TRUE if the path is a directory, FALSE otherwise.
Example:
<?php
var_dump(is_dir('a_file.txt'));
var_dump(is_dir('bogus_dir/abc'));
var_dump(is_dir('..'));
// one dir up
bool(false)
bool(false)
bool(true)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.
