<?php
echo '<h1>Download</h1>';
echo '<br/>';
echo '<div id="download">';
$dir = "images/download/";
if (is_dir($dir)) {
if($dh = opendir($dir)) {
while(($file = readdir($dh))!==false){
echo '<a href="'.$dir.urlencode($file).'">'. str_replace("_"," ", trim($file,'.pdf, .pptx')) . "</a>";
}
closedir($dh);
}
}
echo '</div>';
?>
答案 0 :(得分:1)
您始终必须检查.
和..
目录并忽略它们。它们存在于每个文件夹中。
在命令窗口中执行cd ..
和ls .
时使用的是
<?php
echo '<h1>Download</h1>';
echo '<br/>';
echo '<div id="download">';
$dir = "images/download/";
if (is_dir($dir)) {
if($dh = opendir($dir)) {
while(($file = readdir($dh))!==false){
if ( $file == '.' || $file == '..' ) {
continue;
}
echo '<a href="'.$dir.urlencode($file).'">'. str_replace("_"," ", trim($file,'.pdf, .pptx')) . "</a>";
}
closedir($dh);
}
echo '</div>';
?>