class MyDirectoryIterator extends DirectoryIterator
{
public function getExtension()
{
return pathinfo($this->getFilename(), PATHINFO_EXTENSION);
}
}
DirectoryIterator::getFilename
(PHP 5)
DirectoryIterator::getFilename — Return file name of current DirectoryIterator item.
Descrierea
public string DirectoryIterator::getFilename
( void
)
Get the file name of the current DirectoryIterator item.
Parametri
Această funcție nu are parametri.
Valorile întoarse
Returns the file name of the current DirectoryIterator item.
Exemple
Example #1 A DirectoryIterator::getFilename() example
This example will list the contents of the directory containing the script.
<?php
$dir = new DirectoryIterator(dirname(__FILE__));
foreach ($dir as $fileinfo) {
echo $fileinfo->getFilename() . "\n";
}
?>
Exemplul de mai sus va afișa ceva similar cu:
. .. apple.jpg banana.jpg index.php pear.jpg
Vedeți de asemenea
- DirectoryIterator::getBasename() - Get base name of current DirectoryIterator item.
- DirectoryIterator::getPath() - Get path of current Iterator item without filename
- DirectoryIterator::getPathname() - Return path and file name of current DirectoryIterator item
- pathinfo() - Returns information about a file path
damian at kopiec dot net ¶
1 month ago
kaigillmann at gmxpro dot net ¶
7 years ago
DirectoryIterator extension to get the file-extension:
class MyDirectoryIterator extends DirectoryIterator
{
public function GetExtension()
{
$Filename = $this->GetFilename();
$FileExtension = strrpos($Filename, ".", 1) + 1;
if ($FileExtension != false)
return strtolower(substr($Filename, $FileExtension, strlen($Filename) - $FileExtension));
else
return "";
}
}
