以下のコードは、mysubdirectory というディレクトリ内のすべてのファイルを一覧表示する必要があります。リストには、拡張子 (.pdf) を含めず、各ファイルをダウンロードするためのリンクを含める必要があります。残念ながら、ファイルが上下にリストされていないため、見つけることができないいくつかの間違いがありますが、水平で、拡張子のない最後のファイルのみです。なにか提案を?ありがとう
<?php
$string="";
$fileCount=0;
$filePath=$PATH.'./mysubdirectory/'; # Specify the path you want to look in.
$dir = opendir($filePath); # Open the path
while ($file = readdir($dir)) {
if (eregi("\.pdf",$file)) { # Look at only files with a .pdf extension
$string .= "$file
";
$fileCount++;
}
}
if ($fileCount > 0) {
echo sprintf("<strong>List of Files in %s</strong>%s<strong>Total Files: %s</strong>",$filePath,$string,$fileCount);
}
// pick up the file names, excluding extentions
$info = pathinfo($string);
$number = basename($string,'.'.$info['extension']);
echo "<a href=\"http://www.mysite.com/mysubdirectory/$number.pdf\" target=\"_blank\">$number</a>";
?>