Introduction
In this article I describe the PHP FileSystem functions is_dir, is_executable, is_file and is_link. To learn some other FileSystem functions, go to:
- FileSystem Function in PHP: PART 1
- FileSystem Function in PHP: PART 2
- FileSystem Function in PHP: PART 3
- FileSystem Function in PHP: PART 4
- FileSystem Function in PHP: PART 5
- FileSystem Function in PHP: PART 6
- FileSystem Function in PHP: PART 7
- FileSystem Function in PHP: PART 8
- FileSystem Function in PHP: PART 9
- FileSystem Function in PHP: PART 10
- FileSystem Function in PHP: PART 11
PHP is_dir() Function
The PHP FileSystem is_dir function tells whether the filename is a directory and it returns true if the filename exists and is a directory, otherwise it returns false.
Syntax
Parameter in is_dir function
The parameter of the function is:
Parameter |
Description |
file |
It specifies the file to check. |
Example
An example of the function is:
<?php
$file = "test.txt";
$file1 = "c:/";
if(is_dir($file))
{
echo ("$file is a directory");
}
else
{
echo ("$file is not a directory");
}
echo "</br>";
if(is_dir($file1))
{
echo ("$file1 is a directory");
}
else
{
echo ("$file1 is not a directory");
}
?>
Output
PHP is_executable() Function
The PHP FileSystem is_executable checks whether the specified file is executable or not and it returns true if the file name exists and is executable or false.
Syntax
Parameter in is_executable function
The parameter of the function is:
Parameter |
Description |
file |
It specifies the file to check. |
Example
An example of the function is:
<?php
$file = "install.exe";
if(is_executable($file))
{
echo ("$file is a executable");
}
else
{
echo ("$file is not a executable");
}
?>
Output
PHP is_file() Function
The PHP FileSystem is_file function checks whether the given file is a regular file and it returns true is the filename exists and is a regular file otherwise it returns false.
Syntax
Parameter in is_file function
The parameter of the function is:
Parameter |
Description |
file |
It specifies the file to check. |
Example
An example of the function is:
<?php
$file = "test.txt";
if(is_file($file))
{
echo ("$file is a file");
}
else
{
echo ("$file is not a file");
}
?>
Output
PHP is_link() Function
The PHP FileSystem is_link function checks whether the specified file is a link and it returns true if the file name exists and is a symbolic line otherwise it returns false.
Syntax
Parameter in is_link function
The parameter of the function is:
Parameter |
Description |
file |
It specifies the file to check. |
Example
An example of the function is:
<?php
$file = "test.txt";
if(is_link($file))
{
echo ("$file is a link");
}
else
{
echo ("$file is not a link");
}
?>
Output