我真的很挣钱。我用谷歌搜索了一下,问了我认识的每个人,然后给你这些好人带来麻烦!
我将下面的内容拼凑在一起,将最新的20个文件显示为文件夹中的链接。
我唯一的问题是输出是一个字符串。我真的想把它放在一张桌子里。
每次我尝试它都会在每个字段中转储所有内容,所以我想我需要一些聪明的循环!
有什么想法吗?这是我的代码:
<?php
$dir = "./PDF";
chdir($dir );
$show = 20;
$files = glob( '*.{pdf}', GLOB_BRACE );
usort( $files, create_function('$b, $a', 'return filemtime( $a ) - filemtime( $b );') );
for ( $i = 0; $i < $show; ++$i )
echo '<a href="./PDF/', $file = $files[$i], '" target="_blank">', $file, '</a> - ', date( 'D, M d, Y', filemtime($file) ), ' - ',filesize($file),'kb;<br /><br/>', "\n";
?>
答案 0 :(得分:0)
foreach
可能会让您更轻松,
但看起来你的问题是:
1)。使用.
而非,
进行连接。
2)。把&#34; \ n&#34;最后为#34;新行&#34;
foreach($files as $file){
echo '<tr><td><a href="./PDF/'.$file.'" target="_blank">'.$file.'</a></td><td>'., date( 'D, M d, Y', filemtime($file) ).'</td> <!--etc -->'."\n";//double quotes around "\n"
// for your 20 limit, you could:
i++; if(i>=20){break;}
//但你可以坚持使用for循环,然后取消分配。 }