0

I need to open a folder, list the directories, have the user select the directory of choice (it will be a date), then be presented with a list of pdf files to choose to open. Tried this:

<?php 
$uploadDir = 'files/lap_times';
if ($handle = opendir($uploadDir)) {
   while (false !== ($file = readdir($handle))) {
      if ($file != "." && $file != "..") {
         $file_arr[] = $file;
      }
   }
   closedir($handle);
}
natcasesort($file_arr);
foreach ($file_arr as $file) {
   echo "<b><div class='item'><a href='files/lap_times/" . $file . "' target='_blank'>" . $file . "</a></div></b><p>";
}
?>

and it get's me the pdf's. Tried having it get me the folders, but it left the root open, so I changed it to just show the pdf files. I then zip the previous weeks, and present that as a file choice. Not exactly what I want. So, there would be a folder [Lap_times], and under it subs with dates <8-10-13>, <8-3-13>. In those folders would reside the pdf files. The user could select a date, which would then open a folder of pdf's. And select the one they need, and be done. Have I explained it well enough?

4

1 に答える 1

0

これはあなたが探しているものかもしれません:

$uploadDir = (isset($_GET['date'])) ? 'files/lap_times/' . $_GET['date'] : 'files/lap_times/';

if (is_dir($uploadDir)) {
if ($handle = opendir($uploadDir)) {
   while (false !== ($file = readdir($handle))) {
      if ($file != "." && $file != "..") {
         $file_arr[] = $file;
      }
   }
   closedir($handle);

   natcasesort($file_arr);
foreach ($file_arr as $file) {
    if (isset($_GET['date'])) {
        echo "<b><div class='item'><a href='" . $uploadDir . "/" . $file . "' target='_blank'>" . $file . "</a></div></b><p>";
    } else {
        if (is_dir($uploadDir . "/" . $file)) {
        echo "<b><div class='item'><a href='?date=" . $file . "'>" . $file . "</a></div></b><p>";
        }
    }

}
} 

} else {
    echo "There are no files with this date.";
}

このコードは、異なる日付のフォルダーを示しています。ユーザーが日付をクリックすると、 に移動し?date=[the date]ます。これにより、その日付のファイルが表示され、ファイルを開くことができます。

于 2013-08-12T16:34:59.367 に答える