Цитата:
Сообщение от capitan
$dir = "images";
foreach (scandir($dir) as $f){
if (preg_match("/\.jpg/", $f))
echo "$dir/$f\r\n";
}
|
твой не рекурсивный и не отличает окончания от части слова. Правильно будет примерно так:
PHP код:
$exts = array(
'jpg' => 1,
'jpeg' => 1,
);
function readDirMy($folder) {
global $allFiles;
$files = glob($folder.'/*');
foreach ($files as $file)
if (is_dir($file))
readDirMy($file);
else
$allFiles[] = $file;
}
readDirMy(dirname(__FILE__));
foreach ($allFiles as $fileName) if (
strpos($fileName, '.') !== false &&
key_exists(strtolower(substr($fileName, strpos($fileName, '.') + 1)), $exts))
echo $fileName."<br>\n";