List MP4 files in a directory

Hi Guys,

I have a folder www.toolfolks.com/videos that has various videos in there.

I need to read the directory and the populate a form with some clickable thumbnails of the videos.

ie replicate how youtube works.

I have this php working but not sure whats next.

<?php
echo "Here are our files";
$path = ".";
$dh = opendir($path);
$i=1;
while (($file = readdir($dh)) !== false) {
    if($file != "." && $file != ".." && $file != "index.php" && $file != ".htaccess" && $file != "error_log" && $file != "cgi-bin") {
        echo "<a href='$path/$file'>$file</a><br /><br />";
        $i++;
    }
}
closedir($dh);
?> 

Cheers

Steve Warby.

Hi Steve, I am assuming this a for a WebPage , and not for a android nor IOS app.

If my assumption is correct, a possible solution that I can imagine is the following:

  1. Have your MP4 files in a specific folder of your web hosting. It is important that your application is in the sabe web hosting.
  2. On the MP4 folder, you would need to have a JPG file with a picture of the video (perhaps the best image of the video) and save it in that folder. Therefore you will have one mp4 file and one jpg file per video.
  3. On your application first, you would need to use several image controls (one per video). My recomendation is to generate it at runtime. The path of the image should be relative.
  4. when the image is clicked, then with one video control on top (since you are not going to play several videos at the same time), on the src property you are going to put the relative path and video name.

Your code in general terms is correct; and you would need to use AJAX to retrieve the information of the file names (either for the mp4 and jpg). The code would be something like this:

<?php
$path = ".";
$dh = opendir($path);
$i=1;
while (($file = readdir($dh)) !== false) {
    if($file != "." && $file != ".." && $file != "index.php" && $file != ".htaccess" && $file != "error_log" && $file != "cgi-bin") {
        echo $path."/".$file."|";
        $i++;
    }
}
closedir($dh);
?> 

Please let me know if you need additional assistant.

Best regards,
Adrian.