Friday, February 6, 2026
HomeLanguagesPHP | SplFileInfo isFile() Function

PHP | SplFileInfo isFile() Function

The SplFileInfo::isFile() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to check SplFileInfo object is file or not.

Syntax:

bool SplFileInfo::isFile( void )

Parameters: This function does not accept any parameter.

Return values: This function returns true if file exists, false otherwise.

Below Programs illustrate the SplFileInfo::isFile() function in PHP:

Program 1:




<?php
   
// PHP Program to illustrate 
// Splfileinfo isFile function
   
$file = new SplFileInfo(dirname("gfg.txt"));
$gfg = $file->isFile();
   
// Print result
var_dump($gfg);
echo "</br>";
   
$file = new SplFileInfo(__FILE__);
$gfg = $file->isFile();
   
// Print result
var_dump($gfg);
   
?>


Output:

bool(false)
bool(true) 

Program 2:




<?php 
   
// PHP program to use array to check 
// multiple files 
   
$GFG = array(
    "/home/rajvir/Desktop/neveropen/dummy.php",
    "/home/rajvir/Desktop/gfg_code.cpp",
    "/var/www/html/",
    "frame.php"
);
   
foreach ($GFG as &$file_name) { 
   
    // Create new SplFile Object 
    $file = new SplFileInfo($file_name); 
   
    $gfg = $file->isFile();
   
    // Print result
    var_dump($gfg);
    echo "</br>";
} 
?> 


Output:

bool(false)
bool(false)
bool(true)
bool(false) 

Reference: http://php.net/manual/en/splfileinfo.isfile.php

RELATED ARTICLES

Most Popular

Dominic
32491 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6862 POSTS0 COMMENTS
Nicole Veronica
11986 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12075 POSTS0 COMMENTS
Shaida Kate Naidoo
6995 POSTS0 COMMENTS
Ted Musemwa
7236 POSTS0 COMMENTS
Thapelo Manthata
6946 POSTS0 COMMENTS
Umr Jansen
6931 POSTS0 COMMENTS