我正在编写一个小脚本,我想列出目录的内容,将它们制作成超链接,然后编辑这些超链接以使其看起来很漂亮(即不显示丑陋的超长路径名),然后限制回显的文件数回到浏览器。另外,我只需要回显最新的文件。
我正在考虑使用这个:
<?php
$path = "/full/path/to/files";
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$files .= '<a href="'.$file.'">'.$file.'</a>';
}
}
closedir($handle);
}
?>
或这个:
<?php
$sub = ($_GET['dir']);
$path = 'enter/your/directory/here/';
$path = $path . "$sub";
$dh = opendir($path);
$i=1;
while (($file = readdir($dh)) !== false) {
if($file != "." && $file != "..") {
if (substr($file, -4, -3) =="."){
echo "$i. $file <br />";
}else{
echo "$i. <a href='?dir=$sub/$file'>$file</a><br />";
}
$i++;
}
}
closedir($dh);
?>
但我不想列出这样的文件:
C:/example/example2/Hello.pdf
我想编辑变量。那可能吗?让它说一些像“你好”这样简单的东西。
我也想限制列出的文件数量。例如:只列出前 5 个文件,或最后 5 个文件,等等。是否有一个函数或某种参数?
我感谢任何帮助或朝着正确的方向前进。谢谢