如何在我的网站上显示已上传到服务器文件夹中的文件,以便用户可以下载它们


How can I display the files I have uploaded to a folder in my server on my website so that users can download them?

我刚刚创建了一个网页,允许用户将文件上传到我的public_html文件夹中的文件夹。

move_uploaded_file($_FILES['file']['tmp_name'],"./medetrax_backup/{$_FILES['file']['name']}");

我想知道是否可以通过 php 创建一个网页,显示我在public_html中创建的文件夹中上传的文件,以便在需要时可以下载它们?

我过去用过这个:

$path = "/path/to/folder/";
$dir_handle = opendir($path);
echo "<ul>";
while ($file = readdir($dir_handle)) {
  if ($file != "." && $file != ".." && $file != ".DS_Store") {
    if (!is_dir($file)) {
          echo "<li><a href='" . $file . "'>" . $file . "</a></li>";
        }
    }
}
closedir($dir_handle);