PHP is_dir() function with example

PHP is_dir() function: Here, we will find out about the PHP is_dir() function with its syntax, parameters, returns type, and example.

PHP is_dir() function

The full type of is_dir Is Directory“, the function is_dir() is utilized to check whether a record framework is a registry or whether an index exists or not.

Syntax:

is_dir(directory); 

Parameter(s):

  • registry Directory name (or way) to be checked whether it exists or not.

Return value:

It restores a Boolean value, “Genuine” (1) – if registry exists or “FALSE” (invalid) – if the catalogue doesn’t exist.

Example: PHP code to check whether a registry exists or not

<?php
    //creating directories
    mkdir("/home/folder1");
    mkdir("/home/folder2");
    mkdir("/home/folder3");
    
    //checking directories are exist or not
    echo is_dir("/home/folder1")."<br/>";
    echo is_dir("/home/folder2")."<br/>";
    echo is_dir("/home/folder3")."<br/>";
    echo is_dir("/home/folder4")."<br/>";
    
    //checking through the conditions
    if(is_dir("/home/folder1"))
        echo "/home/folder1 exists"."<br/>";
    else
        echo "/home/folder1 does not exist"."<br/>";

    if(is_dir("/home/folder2"))
        echo "/home/folder2 exists"."<br/>";
    else
        echo "/home/folder2 does not exist"."<br/>";

    if(is_dir("/home/folder3"))
        echo "/home/folder3 exists"."<br/>";
    else
        echo "/home/folder3 does not exist"."<br/>";

    if(is_dir("/home/folder4"))
        echo "/home/folder4 exists"."<br/>";
    else
        echo "/home/folder4 does not exist"."<br/>";        
?>

Output:

1
1
1

/home/folder1 exists
/home/folder2 exists
/home/folder3 exists
/home/folder4 does not exist

Leave a Comment

error: Alert: Content is protected!!