簡體   English   中英

如何使用CSS PHP和HTML顯示多個文件以供下載?

[英]How to display multiple files for download using css php and html?

我仍在學習PHP,並且編寫了代碼來顯示用戶單擊文件名時應下載的文件。 我需要將這些文件顯示在一個表中,該表具有帶有標題(如文件標題 ,上載日期大小)的列 如何以這種方式顯示?

這是我的代碼

 <table id="t02" width="90%" border="1px" cellpadding="5" align="center"> <th> Title </th> <th> Uploaded Date </th> <th> File Size </th> <?php if ($handle = opendir('uploads/it/hnd/')) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { // echo '<a href="/prac/admin/">'.$entry.'</a>'."<br>"; echo "<tr>"; echo "<td>"; echo '<a href="uploads/it/hnd/'.$entry.'"' .'download="'.$entry.'">'.$entry.'</a>'.'</td>'; } } closedir($handle); } ?> </table> 

<table id="t02" width="90%" border="1px" cellpadding="5" align="center">
<tr>
    <th>Title</th>
    <th>Uploaded Date</th>
    <th>File Size</th>
</tr>

<?php
    $files = glob('uploads/it/hnd/*');
    foreach($files as $file){
        echo '<tr>';
        echo '<td><a href="'.$file.'" download="'.$file.'">'.$file.'</a></td>';
        echo '<td>'.date('d M Y [H:i:s]', filemtime($file)).'</td>';
        echo '<td>'.filesize($file).' bytes</td>';
        echo '</tr>';
    }
?></table>
  • 表格的格式最好帶有完整的行和結束標簽。
  • glob()將迅速為您提供文件列表。
  • filesize()將返回filesize()以字節為單位)。
  • 我正在使用filemtime()來獲取文件的最后修改時間。 我認為這足以滿足您的需求。 如果沒有,您可能需要將實際的上載時間存儲在數據庫中以進行檢索,因為文件系統不了解該概念。 我用date()格式化結果。 例如: 02 Jan 2018 [06:15:27]

我建議使用PHP.net ,這是一個非常方便的資源。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM