我有一大堆我正在使用的代码并且工作正常,唯一的问题是当文件夹或文件名中有空格时,它只链接到(或显示)文件中的第一个单词名称
请帮忙,
感谢
<?php
$dirFiles = array();
// opens images folder
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
// strips files extensions
$crap = array(".jpg", ".jpeg", ".JPG", ".JPEG", ".png", ".PNG", ".gif", ".GIF", ".bmp", ".BMP", "_", "-", "error_log", ".php");
$newstring = str_replace($crap, " ", $file );
//asort($file, SORT_NUMERIC); - doesnt work :(
// hides folders, writes out ul of images and thumbnails from two folders
if ($file != "." && $file != ".." && $file != "index.php" && $file != "Thumbnails") {
$dirFiles[] = $file;
}
}
closedir($handle);
}
sort($dirFiles);
foreach($dirFiles as $file)
{
echo "<li>";
echo "<a href=".$file.">".$file."<br></li>";
}
?>
答案 0 :(得分:2)
您有报价问题。您在href
属性周围缺少引号:
echo "<a href=".$file.">".$file."<br></li>";
应该是
echo '<a href="'.$file.'">'.$file.'<br></li>';