PHP | is_executable( )

The is_executable() function in PHP is an inbuilt function which is used to check whether the specified file is an executable file or not. The name of the file is sent as a parameter to the is_executable() function and it returns True if the file is an executable file else it returns False.

Syntax:

bool is_executable($file)

Parameters Used:
The is_executable() function in PHP accepts one parameter.



  • $file: It is a mandatory parameter which specifies the file.

Return Value:
It returns True if the file is an executable file else it returns false.

Exceptions

  • An E_WARNING is emitted on failure.
  • The result of this function are cached and therefore the clearstatcache() function is used to clear the cache.
  • is_executable() function returns false for non-existent files.

Below programs illustrate the is_executable() function.

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
$myfile = "gfg.exe";
  
// checking whether the file is 
// an executable file or not
if (is_executable($myfile))
    echo ("$myfile: executable!");
else
    echo ("$myfile: not executable!");
  
?>

chevron_right


Output:

gfg.exe is executable!

Program 2

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// fileperms() function returns the 
// permission as a number on success
// or FALSE on failure
$permissions = fileperms("gfg.exe");
   
$permvalue = sprintf("%o", $permissions);
   
// checking whether the file is executable
// or not
if (is_executable("gfg.exe"))
    echo ("Executable file and File "
         "Permissions are : $permvalue");
else
    echo ("Not Executable file and File "
          "Permissions are : $permvalue");
  
?>

chevron_right


Output:

Executable file and File Permissions are : 0644

Reference:
http://php.net/manual/en/function.is-executable.php



My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.