PHP 的 is_file() 及 file_exists() 都是用作检查档案是否存在,它们的分别是 file_exists() 输入的参数是目录也会回传 TRUE,而 is_file() 则只会对档案回传 TRUE:
|
1 2 3 4 5 6 7 8 9 |
<?php $path ="/path/to/dir"; if(file_exists($path)){ echo "File Exists"; }else{ echo "File not Exists"; // 如果 /path/to/dir 目录存在会回传 TRUE ?> |
但如果用 is_file(),即使 /path/to/dir 目录存在,仍然会回传 FALSE:
|
1 2 3 4 5 6 7 8 9 |
<?php $path ="/path/to/dir"; if(is_file($path)){ echo "File Exists"; }else{ echo "File not Exists"; // 如果 /path/to/dir 目录存在会回传 TRUE ?> |