filetype
(PHP 4, PHP 5, PHP 7, PHP 8)
filetype — 取得檔案型別
說明
filetype(string
$filename
): string返回檔案的型別。
參數
-
filename
-
檔案的路徑。
返回值
返回檔案的型別。 可能的值有 fifo,char,dir,block,link,file 和 unknown。
如果出錯則返回 false
。如果 stat 呼叫失敗或者檔案型別未知的話
filetype() 還會產生一個 E_NOTICE
訊息。
範例
示例 #1 filetype() 例子
<?php
echo filetype('/etc/passwd'); // file
echo filetype('/etc/'); // dir
?>
錯誤/異常
失敗時拋出E_WARNING
警告。
註釋
注意: 此函式的結果會被快取。參見 clearstatcache() 以獲得更多細節。
小技巧
自 PHP 5.0.0 起, 此函式也用於某些 URL 包裝器。請參見 支援的協議和封裝協議以獲得支援 stat() 系列函式功能的包裝器列表。
參見
- is_dir() - 判斷給定檔名是否是一個目錄
- is_file() - 判斷給定檔名是否為一個正常的檔案
- is_link() - 判斷給定檔名是否為一個符號連線
- file_exists() - 檢查檔案或目錄是否存在
- mime_content_type() - 檢測檔案的 MIME 型別
- pathinfo() - 返回檔案路徑的資訊
- stat() - 給出檔案的資訊