查詢

filetype()函式—用法及示例

「 獲取指定檔案的型別 」


函式名:filetype()

適用版本:PHP 4, PHP 5, PHP 7

用法:filetype() 函式用於獲取指定檔案的型別。

語法:string filetype ( string $filename )

引數:

  • $filename:必需,指定要獲取型別的檔案路徑。

返回值:

  • 返回檔案的型別,可能的值有:file(普通檔案)、dir(目錄)、link(符號連結)、block(塊裝置)、char(字元裝置)、fifo(命名管道)或 unknown(未知)。

示例:

$file = '/path/to/file.txt';
$type = filetype($file);
echo "檔案型別為:" . $type;

輸出:

檔案型別為:file

注意事項:

  • 如果檔案不存在或無法訪問,filetype() 函式將返回 false。
  • 對於符號連結,filetype() 函式將返回 link,而不是連結指向的檔案型別。
補充糾錯
上一個函式: file_exists()函式
熱門PHP函式
分享連結