FileSystem Function in PHP: Part 12

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:

  1. FileSystem Function in PHP: PART 1
  2. FileSystem Function in PHP: PART 2
  3. FileSystem Function in PHP: PART 3
  4. FileSystem Function in PHP: PART 4
  5. FileSystem Function in PHP: PART 5
  6. FileSystem Function in PHP: PART 6
  7. FileSystem Function in PHP: PART 7
  8. FileSystem Function in PHP: PART 8
  9. FileSystem Function in PHP: PART 9
  10. FileSystem Function in PHP: PART 10
  11. 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

is_dir(file)

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


is-dir-function-in-php.gif

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

is_executable(file)

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

is-executable-function-in-php.gif

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

is_file(file)

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


is-file-function-in-php.gif

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

is_link(file)

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

is-link-function-in-php.gif 


Similar Articles