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 ?> |