phpday 2027 - Call for Papers

filetype

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

filetype — Ottiene il tipo di file

Descrizione

function filetype(string $filename): string|false

Restituisce il tipo del file indicato.

Elenco dei parametri

filename

Percorso del file.

Valori restituiti

Restituisce il tipo del file. I valori possibili sono fifo, char, dir, block, link, file, socket e unknown.

Restituisce false se si verifica un errore. filetype() genera inoltre un messaggio E_NOTICE se la chiamata a stat fallisce o se il tipo di file è sconosciuto.

Errori/Eccezioni

In caso di fallimento, viene emesso un E_WARNING.

Esempi

Example #1 Esempio di filetype()

<?php

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

?>

Il precedente esempio visualizzerà:

file
dir

Note

Nota:

I risultati di questa funzione sono memorizzati nella cache. Vedere clearstatcache() per maggiori dettagli.

Suggerimento

A partire da PHP 5.0.0, questa funzione può essere utilizzata anche con alcuni URL wrapper. Fare riferimento a Protocolli e Wrapper supportati per determinare quali wrapper supportano le funzionalità della famiglia stat().

Vedere anche:

  • is_dir() - Dice se la stringa corrisponde ad una directory
  • is_file() - Dice se il nome del file è un file regolare
  • is_link() - Dice se il nome del file è un collegamento simbolico
  • file_exists() - Controlla se un file o una directory esiste
  • mime_content_type() - Detect MIME Content-type for a file
  • pathinfo() - Restituisce informazioni su un percorso di file
  • stat() - Fornisce informazioni su un file

User Contributed Notes 2 notes

up
17
ruach at chpc dot utah dot edu
22 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
6
adlerweb
16 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",...)
Adding new notes is disabled. Please see the links in the Found A Problem? section.
To Top