PHP读取目录下所有文件的代码
时间:2020-11-12 08:10:10|栏目:PHP代码|点击: 次
读取目录下所有文件的代码,可以不管文件名
<?php
$dir = "file";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file!="." && $file!="..") {
echo "<a href=file/".$file.">".$file."</a><br>";
}
}
closedir($dh);
}
}
?>
复制代码 代码如下:
<?php
$dir = "file";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file!="." && $file!="..") {
echo "<a href=file/".$file.">".$file."</a><br>";
}
}
closedir($dh);
}
}
?>