Get the file extension with path information extension in PHP

Description

The following code shows how to get the file extension with path information extension.

Example


<?php//  www.  j a  v a  2  s.  co m

$directory = new DirectoryIterator(__DIR__);
foreach ($directory as $fileinfo) {
    if ($fileinfo->isFile()) {
        echo $fileinfo->getExtension() . "\n";
        $extension = pathinfo($fileinfo->getFilename(), PATHINFO_EXTENSION);
        echo $extension ;
    }
}


?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    File »




Directory
DirectoryIterator
Drive
File
File Permission
File Read Save
FileSystemIterator
Path
Zip