<?php
$goodExt =array("doc","docx","xls","xlsx","ppt","pptx","pdf");
$dirPath = 'test';
if (!is_dir($dirPath)) die("error (1): <b>$dirPath</b> не папка.");
if (!is_readable($dirPath)) die("error (2): нехватает прав для чтения <b>$dirPath</b>.");
$fileInDir = scandir ($dirPath);
unset ($fileInDir[0],$fileInDir[1]);
foreach ($fileInDir as $file) {
if (is_dir($file)) continue;
$fileExt = pathinfo($dirPath. DIRECTORY_SEPARATOR .$file, PATHINFO_EXTENSION);
if (array_search($fileExt, $goodExt)!==FALSE) {
$findFile[] = array (
'path' => $file,
'ext' => $fileExt,
'name' => str_replace($ext, NULL, $file)
);
}
}
?>
<h3>Всего файлов и каталогов: <?=sizeof($fileInDir)?></h3>
<ul id="files">
<?foreach ($findFile as $file):?>
<li>
<a class="<?=$file['ext']?>" href="<?=$dirPath. DIRECTORY_SEPARATOR .$file['path']?>"><?=$file['name']?></a>
</li>
<?endforeach;?>
</ul>Add a code snippet to your website: www.paste.org