I have a bunch of videos of various formats and images that I show on a web page. To make things easy on myself I wrote this to scan the folder where the videos sit and to display them in a way that makes sense. So this script reads the file list into an array and then sorts it by time (based on weeks in the year). Then I show the links arranged by folders for each week of the year. That folder is link and when clicked it shows/hides the videos for that week.
Enjoy
Bastien
<html>
<title>Bastien's Video List</title>
<head>
<script language='javascript'>
function show_list(d)
{
var sInline = 'inline';
if (document.getElementById(d).style.display == 'inline'){ sInline='none'; }
document.getElementById(d).style.display = sInline;
}//end func
</script>
</head>
<body>
<?php
//preview video scripts
//read in the dir files and display them as links
//onclicking the link reloads the page with the video
//organize the vids by date...
<?php
function show_video()
{
$file = '';
$type = '';
$file = @$_GET['v'];
$type = stristr($file,".");
//check for file
if (!file_exists("./vids/$file"))
{
//file doesn't exist
confirm("File can't be found. Please try choosing it again from the list.");
show_list();
die();
}//end if
echo "<center>";
//check file type
if (($type == ".mov")||($type == ".qt")||($type == ".mp4"))
{
//if quicktime (.mov, .qt)
?>
echo "<br><br><br><a href='vids.php'>Back to list</a></center>";
}//end function
function show_list2()
{
//organize vids by data
//read into array
//sort array
//show folders in collapsed tables
//onclick folder/date to 'show folder contents'
echo "<center><h2>I take no responsibility if you ARE OFFENDED by these videos.<br /> YOU CHOOSE TO CLICK THE LINK!</h2></center>";
echo "<table width=75% cellpadding=5 cellspacing=0 align=center><tr valign=top><td>";
$dir = './vids/';
$aVids = array();
//get data into array
//open the main video dir
if ($handle = opendir($dir))
{
//loop thru the files in the dir
while (false !== ($file = readdir($handle)))
{
//check to make sure the file is not a directory
if ($file != "." && $file != "..")
{
//reset the new var to empty string
$new = '';
//clear the stats cache of file data
clearstatcache();
//get the file name and find out if its a new file
if (file_exists($dir.$file))
{
//check to see if the video is 'new' and needs the new tag
if ((time() - filemtime($dir.$file)) < 345600)
{
$new = "\n\t\t <span style=\"font-weight:bold; color:red; font-size:smaller;\">New!</span>";
}
//add the video to the array
$aVids[] = array('file'=>$file, 'dtime'=>filemtime($dir.$file), 'week'=>date("W",filemtime($dir.$file)), 'new'=> $new);
}//end if
}//end if
}//loop
}//end if
// Turn array into a list of columns
foreach ($aVids as $key => $row) {
$file[$key] = $row['file'];
$week[$key] = $row['week'];
$new[$key] = $row['new'];
}
// sort the arays
array_multisort($week,SORT_DESC,$aVids);