filetype

(PHP 3, PHP 4, PHP 5)

filetype -- 取得文件类型

说明

string filetype ( string filename )

返回文件的类型。可能的值有 fifo,char,dir,block,link,file 和 unknown。

如果出错则返回 FALSE。如果 stat 调用失败或者文件类型未知的话 filetype() 还会产生一个 E_NOTICE 消息。

注: 本函数的结果会被缓存。更多信息参见 clearstatcache()

提示: PHP 5.0.0 起本函数也可被某些 URL wrapper 使用。参考附录 L 来看哪些 wrapper 支持 stat() 系列函数的功能。

例子 1. filetype() 例子

<?php

echo filetype('/etc/passwd');  // file
echo filetype('/etc/');        // dir

?>

参见 is_dir()is_file()is_link()file_exists()stat()mime_content_type()


add a note add a note User Contributed Notes
Guillaume Cocatre-Zilgien
01-Nov-2004 09:42
"socket" should be added to the list of possible values that can be returned by filetype(). I have tested it with versions 4.3.0 and 5.0.2 of PHP.
ruach at chpc dot utah dot edu
11-Mar-2004 09:11
There are 7 values that can be returned. Here is a list of them and what each one means

block: block special device

char: character special device

dir: directory

fifo: FIFO (named pipe)

file: regular file

link: symbolic link

unknown: unknown file type