<?php
myDir('../zd');//这里zd改成当前目录名
function myDir($dir = __file__)
{
$handle = @opendir($dir) or die("Cannot open " . $dir);
while ($file = readdir($handle)) {
if ($file != "." && $file != "..") {
if(pathinfo($file,PATHINFO_EXTENSION)=="txt"){
$pach2=getcwd();
$test="http://".$_SERVER['HTTP_HOST']."/".basename($pach2).'/'.$file;
$fil=pathinfo($file,PATHINFO_FILENAME);
echo "<a href=$test download=$file>$fil</a><br>";
};
};
};
// 关闭目录读取
closedir($handle);
}
?>
实现了列出当前目录的txt文件并显示下载按钮,