PHP | filetype 函數
怎樣獲取文件類型
最近更新時間 2021-01-05 16:57:17
filetype 函數獲取文件類型。
filetype() 函數返回指定文件的類型。返回值為字符串,可能包括 fifo、char、dir、block、link、file 和 unknown。
函數定義
    filetype ( string $filename ) : string
  
  // 源文件位於:ext/standard/filestat.c
# 函數定義
FileFunction(PHP_FN(filetype), FS_ATIME)
...
php_stat(filename, filename_len, funcnum, return_value);
...
  參數
- checkfilename - 文件的路徑。
 
返回值
- checkstring - 返回文件的類型,失敗時返回 false。
 
示例1: - 使用 filetype() 函數獲取文件類型。
<?php
/**
 * PHP filetype() 函數獲取文件類型。
 *
 * @since Version 1.0.0
 * @filesource
 */
// 文件類型
$filetype = filetype('foo.txt');
echo $filetype.PHP_EOL;
  file