Home » PHP

PHP is_dir() function with example

PHP is_dir() function: Here, we are going to learn about the PHP is_dir() function with its syntax, parameters, returns type, and example.
Submitted by IncludeHelp, on August 11, 2019

PHP is_dir() function

The full form of is_dir is "Is Directory", the function is_dir() is used to check whether a file system is a directory or whether a directory exists or not.

Syntax:

    is_dir(directory);

Parameter(s):

  • directory – Directory name (or path) to be checked whether it exists or not.

Return value:

It returns a Boolean value, "TRUE" (1) – if directory exists or "FALSE" (null) – if the directory does not exist.

Example: PHP code to check whether a directory 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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.