0

我有一段 php,如果指定的文件夹中有文件,它将显示文件名、创建日期并显示下载按钮,如果文件夹为空,它将不显示任何内容。这很好用,但如果我在文件夹中有多个文件,它会将所有文件名捆绑在一起 - 我想要的是为每个文件显示的单独信息。

为了帮助您理解问题,这里有一张显示问题和代码的图像。我自己走了很远,但它在我的头上,我只是看不到解决问题的简单方法。该代码可能看起来非常尴尬和奇怪,因为我对此完全陌生,但它在浏览器上看起来很正确。我真的很感激任何帮助谢谢。

这是问题的图片:http: //i46.tinypic.com/m79cvs.png

    <?php if (!empty($thelist)) { ?>
<p class="style12"><u>Fix</u></p>
<p class="style12"><?=$thelist?><?php echo " - " ?> <?php $filename = '../../customers/client1/client1.fix.exe';
if (file_exists($filename)) {
    echo "" . date ("m/d/Y", filemtime($filename));
}
?> <?php echo " - <a href='download.php?f=client1/client1.fix.exe'><b>Download</b></a>&nbsp;&nbsp;&nbsp;<a     href='download.php?f=client1/client1.fix.exe'>
<img src='../css/images/dlico.png' alt='download' width='35' height='32'     align='absmiddle' /></a>" ?>
</p>
<?php } ?>
4

1 回答 1

0

列表 ( $thelist) 包含您的文件,是吗?您不是在处理$thelist,而是在处理$filename硬编码的字符串。为什么?目前您正在输出<?=$thelist?>,它看起来像文件名中的串联字符串。我建议这$thelist应该是你的文件数组。然后,您可以遍历文件并为每个条目动态输出 html。

<?php
    // define your directory here
    $directory = xy; 

    // fetches all executable files in that directory and loop over each
    foreach(glob($directory.'/*.exe') as $file) { 
        // output each name and mtime
        echo $file . '-' . date ("m/d/Y", filemtime($file));
        // or you might also build links dynamically
        // $directory needs to be added here
        echo '<a href="'.$file.'">'.$file.' - Size: '.filesize($file).'</a>';
    }
?>
于 2012-07-10T12:41:33.707 回答