filetype

(PHP 4, PHP 5, PHP 7, PHP 8)

filetypeLê o tipo do arquivo

Descrição

filetype(string $filename): string|false

Retorna o tipo do arquivo.

Parâmetros

filename

Caminho até o arquivo.

Valor Retornado

Retorna o tipo do arquivo. Os valores possíveis são fifo, char, dir, block, link, file, socket e unknown (desconhecido).

Retorna false se ocorrer algum erro. filetype() também produzirá uma mensagem E_NOTICE se a chamada stat falhar ou se o tipo do arquivo for desconhecido.

Erros/Exceções

Em caso de falha, um E_WARNING será emitido.

Exemplos

Exemplo #1 Exemplo de filetype()

<?php

echo filetype('/etc/passwd');
echo
"\n";
echo
filetype('/etc/');

?>

O exemplo acima produzirá:

file
dir

Notas

Nota: Os resultados desta função são armazenados em cache. Consulte a função clearstatcache() para mais detalhes.

Dica

A partir do PHP 5.0.0, esta função também pode ser usada com alguns empacotadores de URL. Consulte os Protocolos e empacotadores suportados para determinar quais empacotadores suportam a família de funções stat().

Veja Também

  • is_dir() - Diz se o caminho é um diretório
  • is_file() - Informa se o arquivo é um arquivo comum
  • is_link() - Informa se o arquivo é uma ligação simbólica
  • file_exists() - Verifica se um arquivo ou diretório existe
  • mime_content_type() - Detecta o tipo de conteúdo MIME de um arquivo
  • pathinfo() - Retorna informações sobre um caminho de arquivo
  • stat() - Obtém informações sobre um arquivo

adicione uma nota

Notas Enviadas por Usuários (em inglês) 3 notes

up
21
ruach at chpc dot utah dot edu
21 years ago
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
up
7
adlerweb
14 years ago
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",...)
up
-2
7r6ivyeo at mail dot com
16 years ago
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.
To Top