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