The change doesn't appear to be documented, so I thought I would mention it. In php5, as opposed to php4, you can no longer rely on is_executable to check the executable bit on a directory in 'nix. You can still use the first note's method to check if a directory is traversable:
@file_exists("adirectory/.");
is_executable
(PHP 4, PHP 5)
is_executable — 判断给定文件名是否可执行
说明
bool is_executable
( string
$filename
)
如果文件存在且可执行则返回 TRUE。
is_executable() 自 PHP 5.0.0 版起可用于 Windows。
Example #1 is_executable() 例子
<?php
$file = '/home/vincent/somefile.sh';
if (is_executable($file)) {
echo $file.' is executable';
} else {
echo $file.' is not executable';
}
?>
Note: 此函数的结果会被缓存。参见 clearstatcache() 以获得更多细节。
Tip
自 PHP 5.0.0 起, 此函数也用于某些 URL 包装器。请参见 Supported Protocols and Wrappers以获得支持 stat() 系列函数功能的包装器列表。
参数
-
filename -
Path to the file.
返回值
Returns TRUE if the filename exists and is executable, or FALSE on
error.
更新日志
| 版本 | 说明 |
|---|---|
| 5.0.0 | is_executable() became available with Windows |
范例
Example #2 is_executable() example
<?php
$file = '/home/vincent/somefile.sh';
if (is_executable($file)) {
echo $file.' is executable';
} else {
echo $file.' is not executable';
}
?>
错误/异常
失败时抛出E_WARNING警告.
注释
Note: 此函数的结果会被缓存。参见 clearstatcache() 以获得更多细节。
Tip
自 PHP 5.0.0 起, 此函数也用于某些 URL 包装器。请参见 Supported Protocols and Wrappers以获得支持 stat() 系列函数功能的包装器列表。
Buuyo
06-Aug-2004 03:51
david at littlesystems dot com dot au
01-Jun-2002 11:38
to test whether the directory /home/david is executable (regardless of whether it is readable or writeable), issue the command:
$my_isWriteable = @file_exists("/home/david/.")
the @ gets rid of the warning when this command fails when the directory is not executable.
