DirectoryIterator::getType

(PHP 5, PHP 7, PHP 8)

DirectoryIterator::getType現在の DirectoryIterator アイテムのタイプを判定する

説明

public DirectoryIterator::getType(): string

現在の DirectoryIterator アイテムのファイルタイプを判定します。 filelink あるいは dir のいずれかとなります。

パラメータ

この関数にはパラメータはありません。

返り値

ファイルタイプを文字列で返します。 filelink あるいは dir のいずれかとなります。

例1 DirectoryIterator::getType() の例

<?php
$iterator 
= new DirectoryIterator(dirname(__FILE__));
foreach (
$iterator as $fileinfo) {
    echo 
$fileinfo->getFilename() . " " $fileinfo->getType() . "\n";
}
?>

上の例の出力は、 たとえば以下のようになります。

. dir
.. dir
apple.jpg file
banana.jpg file
example.php file
pear.jpg file

参考

add a note add a note

User Contributed Notes 1 note

up
3
boards at gmail dot com
18 years ago
Note that this function returns the file type (e.g. "file", "dir", etc.) and not the MIME type.  To do that, you might want to use this:
<?php
for
(
 
$dir = new DirectoryIterator('/some/directory');
 
$dir->valid();
 
$dir->next()
)
{
 
$mime = mime_content_type($dir->getPathname());
}
?>
To Top