首頁  >  文章  >  後端開發  >  php目錄不存在是怎麼判斷的

php目錄不存在是怎麼判斷的

藏色散人
藏色散人原創
2020-07-07 10:48:192686瀏覽

php目錄不存在的判斷方法:先建立PHP範例檔案;然後輸入判斷語句為「bool file_exists (string $filename)」;最後在瀏覽器中執行該檔案即可判斷目錄是否存在。

php目錄不存在是怎麼判斷的

php判斷目錄是否存在

#file_exists — 檢查檔案或目錄存在

說明

bool file_exists    ( string $filename   )

檢查檔案或目錄是否存在。

參數

filename      

檔案或目錄的路徑。      

      在 Windows 中要使用 //computername/share/filename 或    \\computername\share\filename 來檢查網路中的共用檔案。      

#  若 filename 指定的檔案或目錄存在則傳回    TRUE,否則傳回 FALSE。  

Note:    

 This function will return FALSE for symlinks pointing to non-existing    files.

Warning    

如果因為安全模式的限製而導致無法存取檔案的話,則函數會傳回     FALSE。然而,可以使用     include 來包含,如果檔案在     safe_mode_include_dir     所指定的目錄中。

Note:    

   The check is done using the real UID/GID instead of the effective one.    

Note: 因為PHP 的整數型別是有符號整數且有許多有符號整數平台使用32位元整數,     對2GB以上的檔案,一些檔案系統函數可能傳回無法預期的結果。

範例

Example #1 測試一個檔案是否存在

 

<?php
$filename = &#39;/path/to/foo.txt&#39;;
 
if (file_exists($filename)) {
    echo "文件 $filename 存在";
} else {
    echo "文件 $filename 不存在";
}
?>
//以上内容来自官方PHP开发帮助文档

更多相關知識,請造訪PHP中文網# !

以上是php目錄不存在是怎麼判斷的的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn