Get base name of current DirectoryIterator item in PHP
Description
The following code shows how to get base name of current DirectoryIterator item.
Example
//from w ww. jav a 2 s.c o m
//This example will list the full base name and the base
//name with suffix .jpg removed for the files in the directory containing the script.
<?php
$dir = new DirectoryIterator(dirname(__FILE__));
foreach ($dir as $fileinfo) {
if ($fileinfo->isFile()) {
echo $fileinfo->getBasename() . "\n";
echo $fileinfo->getBasename('.jpg') . "\n";
}
}
?>
The code above generates the following result.