Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as PHP by webpavilion ( 15 years ago )
<?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>

 

Revise this Paste

Children: 63158
Your Name: Code Language: