filetype
(PHP 4, PHP 5)
filetype — Получить тип файла
Описание
Возвращает тип файла. Возможными значениями являются fifo, char, dir, block, link, file и unknown.
Возвращает FALSE в случае возникновения ошибки. filetype() также вызовет сообщение E_NOTICE при неудачной попытке получения информации о файле или если тип файла неизвестен.
Замечание: Результаты этой функции кэшируются. Более подробную информацию смотрите в разделе clearstatcache().
Начиная с PHP 5.0.0, эта функция также может быть использована с некоторыми упаковщиками url. Список упаковщиков, поддерживаемых семейством функций stat(), смотрите в List of Supported Protocols/Wrappers.
Пример #1 Пример использования функции filetype()
<?php
echo filetype('/etc/passwd'); // file
echo filetype('/etc/'); // dir
?>
См. также описание функций is_dir(), is_file(), is_link(), file_exists(), stat() и mime_content_type().
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с файловой системой
- Функции для работы с файловой системой
- basename
- chgrp
- chmod
- chown
- clearstatcache
- copy
- delete
- dirname
- disk_free_space
- disk_total_space
- diskfreespace
- fclose
- feof
- fflush
- fgetc
- fgetcsv
- fgets
- fgetss
- file_exists
- file_get_contents
- file_put_contents
- file
- fileatime
- filectime
- filegroup
- fileinode
- filemtime
- fileowner
- fileperms
- filesize
- filetype
- flock
- fnmatch
- fopen
- fpassthru
- fputcsv
- fputs
- fread
- fscanf
- fseek
- fstat
- ftell
- ftruncate
- fwrite
- glob
- is_dir
- is_executable
- is_file
- is_link
- is_readable
- is_uploaded_file
- is_writable
- is_writeable
- lchgrp
- lchown
- link
- linkinfo
- lstat
- mkdir
- move_uploaded_file
- parse_ini_file
- parse_ini_string
- pathinfo
- pclose
- popen
- readfile
- readlink
- realpath_cache_get
- realpath_cache_size
- realpath
- rename
- rewind
- rmdir
- set_file_buffer
- stat
- symlink
- tempnam
- tmpfile
- touch
- umask
- unlink
Коментарии
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
I use the CLI version of PHP on Windows Vista. Here's how to determine if a file is marked "hidden" by NTFS:
<?php
function is_hidden_file($fn) {
$attr = trim(exec('FOR %A IN ("'.$fn.'") DO @ECHO %~aA'));
if($attr[3] === 'h')
return true;
return false;
}
?>
Changing <?php if($attr[3] === 'h') ?> to <?php if($attr[4] === 's') ?> will check for system files.
This should work on any Windows OS that provides DOS shell commands.
filetype() does not work for files >=2GB on x86 Linux. You can use stat as a workarround:
$type=trim(`stat -c%F $file`);
Note that stat returns diffenerent strings ("regular file","directory",...)