[英]How to display multiple files for download using css php and html?
I am still learning PHP and I have written a code to show files that are supposed to be downloaded when a user clicks the file name. 我仍在学习PHP,并且编写了代码来显示用户单击文件名时应下载的文件。 I need the files to be displayed in a table that has columns with titles such as file title , uploaded date , and size . 我需要将这些文件显示在一个表中,该表具有带有标题(如文件标题 ,上载日期和大小)的列 。 How can I display in such a way? 如何以这种方式显示?
this is my code 这是我的代码
<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()
will quickly get you a list of files. glob()
将迅速为您提供文件列表。 filesize()
will return the size of a file in bytes. filesize()
将返回filesize()
以字节为单位)。 filemtime()
to get the last-modified time of the file. 我正在使用filemtime()
来获取文件的最后修改时间。 I'm assuming this is sufficient for your needs. 我认为这足以满足您的需求。 If not, you'll likely need to store an actual upload time in a database for retrieval as the file system doesn't understand that concept. 如果没有,您可能需要将实际的上载时间存储在数据库中以进行检索,因为文件系统不了解该概念。 I'm formatting the result with date()
. 我用date()
格式化结果。 An example would be: 02 Jan 2018 [06:15:27]
. 例如: 02 Jan 2018 [06:15:27]
。 I recommend using PHP.net , it's a very handy resource. 我建议使用PHP.net ,这是一个非常方便的资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.