この PHP コードは、指定したディレクトリを反復処理し、見つかったすべての PDF ファイルを という配列に格納します$files
。を調整する必要がある場合があります$dir
。
$dir = 'html_public/uploadedfiles/files_type_a/2010/'; //directory to pull from
$skip = array('.','..'); //a few directories to ignore
$dp = opendir($dir); //open a connection to the directory
$files = array();
if ($dp) {
while ($file = readdir($dp)) {
if (in_array($file, $skip)) continue;
if (is_dir("$dir$file")) {
$innerdp = opendir("$dir$file");
if ($innerdp) {
while ($innerfile = readdir($innerdp)) {
if (in_array($innerfile, $skip)) continue;
$arr = explode('.', $innerfile);
if (strtolower($arr[count($arr) - 1]) == 'pdf') {
$files[$file][] = $innerfile;
}
}
}
}
}
}
この部分は、HTML テーブルを作成し、該当するすべてのファイルを表示します。
<table>
<? foreach ($files as $directory => $inner_files) { ?>
<tr>
<td>Folder: <?= $directory ?></td>
</tr>
<? foreach ($inner_files as $file) { ?>
<tr>
<td>File: <?= $directory ?>/<?= $file ?></td>
</tr>
<? } ?>
<? } ?>
</table>