[英]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.