PHP is_executable() Function
The PHP is_executable() function checks whether a file exists and is executable.
Note: The results of this function are cached. Use clearstatcache() function to clear the cache.
Syntax
is_executable(filename)
Parameters
filename |
Required. Specify the path to the file to check. |
Return Value
Returns true if the filename exists and is executable, or false on error.
Exceptions
Upon failure, an E_WARNING is thrown.
Example:
Lets assume that we have a file called test.txt and setup.exe in the current working directory. The example below demonstrates on using this function to check if these files are executable or not.
<?php $file1 = 'test.txt'; $file2 = 'setup.exe'; //checking if $file1 is executable if(is_executable($file1)) { echo "The file $file1 is executable.\n"; } else { echo "The file $file1 is not executable.\n"; } //checking if $file2 is executable if(is_executable($file2)) { echo "The file $file2 is executable.\n"; } else { echo "The file $file2 is not executable.\n"; } ?>
The output of the above code will be:
The file test.txt is not executable. The file setup.exe is executable.
❮ PHP Filesystem Reference