0

I host my personal weather station information on a website from my Synology NAS. I recently added a weather webcam and want to create a list of daily videos for users to download from a page on my website. The entire website is php-based and I wrote some code that partially does what I want. It creates a list of the daily mp4 files but I want to display them in chronological order by filename and in addition to the mp4 files the webpage shows a "." and a "..". The mp4 files are stored on my NAS in this directory path: video/archive/2022/ and my weather website page that lists the files is at https://novawx.dscloud.me/2022-video-archive.php. Here is the php code.

<?php
$directory = "video/archive/2022/";

if (is_dir($directory)){
  if ($opendirectory = opendir($directory)){
    while (($file = readdir($opendirectory)) !== false){
      echo "<a href='https://novawx.dscloud.me/$directory" . "$file' 
target='_blank'>$file</a>"."<br>";
    }
    closedir($opendirectory);
  }
}
?>
weatherdoc
  • 13
  • 4
  • 2
    I don't see a question or a problem description... Maybe you want to start with the [tour] and read [ask]? – Ulrich Eckhardt Mar 03 '22 at 14:54
  • You want to sort by filename, those filenames just happen to be dates, but you're not sorting chronologically. You could do that, files have several dates, like when they were created, modified or accessed. – KIKO Software Mar 03 '22 at 14:57
  • As I stated, the question is: "I want to display them in chronological order by filename" and right now they are displayed randomly, neither by filename nor creation date. The filename format is YYYY_MM_DD.mp4. For example, if I have 5 files from Feb 24-28, 2022, I'd like to list them as: 2022_02_24, 2022_02_25, 2022_02_26, 2022_02_27, 2022_02_28. Similar to sorting by name in Windows Explorer. And the question I wasn't specific about is how to not display the "." and ".." as part of the filename list. – weatherdoc Mar 03 '22 at 17:01
  • Likely want to use `scandir` instead of `opendir` because it supports sorting: this answer provides details and neatly explains the differences in the three approaches of: `opendir` ; `scandir` ; and `DirectoryIterator`: https://stackoverflow.com/a/23145427/17856705 . In the example provided you would add `.` and `..` to the blacklist specified and any other file patterns to be ignored. – Computable Mar 03 '22 at 17:17
  • Thanks for the tip and link to the other example. I was able to use some of that code along with what I already had to reach a good solution. Now the files are in chronological order by filename and the unwanted hidden files ("." and "..") are not displayed. – weatherdoc Mar 03 '22 at 19:08

0 Answers0