PHP : Video List

3 Mar

<?
//get files in the current directory
$handle=opendir(‘.’);
while ($file = readdir($handle)) {
if (substr($file, -3) == “avi” | substr($file, -3) ==
“mpg” | substr($file, -3) == “mov” | substr($file, -3) == “ram”) {
$files[] = array(name => $file, size =>
intval(filesize($file)/1024));
}

}
closedir($handle);
sort($files);

//begin the html page and table
echo “<html>\n<head>\n<meta http-equiv=\”content-type\”
content=\”text/html; charset=windows-1252\”>\n<title>Files</title>\n<body
bgcolor=\”#ffffff\”>\n<b><font face=\”arial, helvetica,
geneva\”>Files:</font></b><br><br>\n”;
echo “<table bordercolor=\”#000000\” border=\”1\”
cellspacing=\”0\” cellpadding=\”0\”>\n\t<tr>\n\t\t<td
align=\”center\”><font size=\”2\” face=\”arial, helvetica,
geneva\”><b>Name</b></font></td>\n\t\t<td align=\”center\”><font
size=\”2\” face=\”arial, helvetica,
geneva\”><b>Size</b></font></td>\n\t</tr>\n”;

//loop through the table rows
for ($i = 0; $i <= count($files)-1; $i++) {
$len = strlen($files[$i][name]);
$len = $len-4;
$img = “images/”.substr(“{$files[$i][name]}”, 0,
$len).”.jpg”;
echo “\t<tr>\n\t\t<td align=\”left\”><a
href=\”{$files[$i][name]}\”><img border=\”0\” src=\”$img\”
alt=\”{$files[$i][name]}\”></a></font></td>\n\t\t<td
align=\”center\”><font size=\”2\” face=\”arial, helvetica,
geneva\”> {$files[$i][size]} kb</font></td>\n\t</tr>\n”;
}
echo “</table>\n</body>\n</html>”;
?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: