Here's what I came up with in the end... it works... whether it does so with any grace or dignity is a different matter!
Pre-requisites (following is for FreeBSD btw)
Code:
Step 1 - Install FFMpeg (converts video formats)
cd /usr/ports/multimedia/ffmpeg
make config (plonk a cross in LAME libmp3codec box >> OK )
&& make install clean
Step 2 - Install Ruby (interpreter for FLVTool2)
cd /usr/ports/lang/ruby18
&& make install clean
Step 3 - Install FLVTool2 (injects metadata into FLV files)
cd /usr/ports/multimedia/ruby-flvtool2
&& make install clean
Step 4 - Configure Ruby
ruby setup.rb config
ruby setup.rb setup
The form (upload.php):
Code:
<?php
$maxsize = ini_get('upload_max_filesize');
if (!is_numeric($maxsize)) {
if (strpos($maxsize, 'G') !== false)
$size = intval($maxsize)*1024*1024*1024;
elseif (strpos($maxsize, 'M') !== false)
$size = intval($maxsize)*1024*1024;
elseif (strpos($maxsize, 'K') !== false)
$size = intval($maxsize)*1024; }
echo "<p style=\"text-align:center;\"><strong>This facility should be used within school only.</strong> Please do not attempt to upload files from home.<br /><br />Upload only mpg, avi, wmv or mov files.<br />Ensure there are no spaces in the filename, and that the file is less than ".$maxsize."b in size.<br />If your file is larger than ".$maxsize."b you will need to take it to ICT Support to be put on the site.<br /><br />To remove spaces, right-click on the file and select <strong>\"Rename\"</strong>. You should then replace any spaces in the filename with underscores ( _ )<br />Underscore = shift and the minus key on the top row of the keyboard to the right of the zero.<br />To check the file size, right-click on the file and select <strong>\"Properties\"</strong>. The <strong>Size on Disk:</strong> field must be LESS than ".$maxsize."b</p>";
echo "<div style=\"width:250px;margin-left:auto;margin-right:auto;\"><form enctype=\"multipart/form-data\" action=\"processupload.php\" method=\"POST\">
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\".$size.\" />
Send this file: <input name=\"userfile\" type=\"file\" />
<br />Choose subject area:
<select name=\"subjectarea\" id=\"subject\">
<option value=\"eng\">English</option>
<option value=\"drama\">Drama</option>
<option value=\"music\">Music</option>
<option value=\"PE\">PE</option>
<option value=\"history\">History</option>
<option value=\"geography\">Geography</option>
<option value=\"MFL\">MFL</option>
<option value=\"ict\">ICT</option>
<option value=\"maths\">Maths</option>
<option value=\"phse\">PHSE</option>
<option value=\"re\">RE</option>
<option value=\"Science\">Science</option>
<option value=\"public\">Public Area</option>
</select>
<br /><br />
<input type=\"submit\" value=\"Send File\" /></form></div>";
?>
Processing the upload form (processupload.php):
Code:
<?php
error_reporting(E_ALL);
ini_set("session.gc_maxlifetime","10800");
$finallocation = $_REQUEST['subjectarea'];
$allowable_ext = array('avi','mpg','mov','wmv');
$pieces = explode('.', $_FILES['userfile']['name']);
$ext = $pieces[count($pieces) - 1];
if(!in_array($ext, $allowable_ext)) {
echo "Error Code 001: Invalid filetype or no file selected - you may only upload files smaller than 100Mb which end in .mpg, .avi, .wmv or .mov.<br /><br /><a href=\"upload.php\">Return to the Upload Form</a>\n"; exit;
}
$uploaddir = '/home/user/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
$origname = basename($_FILES['userfile']['name']);
$newname = substr($origname, 0, -4);
$newfile = $uploaddir . $newname;
$uf = escapeshellcmd($uploadfile);
$nf = escapeshellcmd($newfile);
if ((($_FILES['userfile']['type'] == "video/mpeg")
|| ($_FILES['userfile']['type'] == "video/msvideo")
|| ($_FILES['userfile']['type'] == "video/quicktime")
|| ($_FILES['userfile']['type'] == "video/x-ms-wmv"))
&& ($_FILES['userfile']['size'] < 104857600))
{
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.<br />\n";
} else {
echo "Error Code 002: File upload was unsuccesful.<br />\n";
}
if (chmod($uploadfile, 0744)) {
echo "CHMOD was succesful.<br />\n";
} else {
echo "Error Code 003: CHMOD failed. File is executable.<br />\n";
}
$last_line = system('ffmpeg -i '.$uf.' '.$nf.'.flv', $retval);
$last_line = system('cat '.$nf.'.flv | flvtool2 -U stdin '.$nf.'.flv', $retval);
echo "Source file has been succesfully converted to FLV...<br />";
exec('rm '.$uf.'');
echo "Original source file has now been removed...<br />";
exec('cp '.$nf.'.flv /home/user/public_html/video/'.$finallocation.'/');
exec('rm '.$nf.'.flv');
echo "The converted FLV file has now been added to your chosen subject area's playlist.<br />";
echo "For reference, the chosen subject area was <strong>".$finallocation."</strong>.<br />You may now <a href=\"../protected/subjectmedia.php\"><strong>head to the playlist</strong></a> to verify the file.";
}
else { echo "Error Code 004: Invalid filetype - you may only upload files smaller than 100Mb which end in .mpg, .avi, .wmv or .mov.<br /><br /><a href=\"upload.php\">Go back to Upload Form</a>\n"; }
?>
Building playlist on-the-fly (SUBJECT_playlist.php):
Code:
<?php
$filter = ".flv";
$directory = "SUBJECT/"; //<< ie: Eng / Maths / Science etc...
$site = "http://www.site.com/video/";
@$d = dir($directory);
if ($d) {
while($entry=$d->read()) {
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false)) {
$items[] = $entry;
}
}
$d->close();
sort($items);
}
header("content-type:text/xml;charset=utf-8");
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <title>SUBJECT Media Playlist</title>\n";
echo " <info>http://www.site.com</info>\n";
echo " <trackList>\n";
foreach($items as $value)
{
$title = preg_replace('/.flv/', '', $value);
$title = preg_replace('/_/', ' ', $title);
print " <track>\n";
print " <title>" . $title . "</title>\n";
print " <location>" . $site . '/video/' . $directory . '/' . $value . "</location>\n";
print " </track>\n";
}
echo " </trackList>\n";
echo "</playlist>\n";
?>
And the player itself (using JW Player & SWFObject):
Code:
<script type="text/javascript" src="http://www.site.com/js/swfobject.js"></script>
<div id="player">Please enable Javascript to use our Media
Player</div>
<script type="text/javascript">
var so = new SWFObject('http://www.site.com/video/mediaplayer.swf','mpl','620','260','8');
so.addParam('allowscriptaccess','always');
so.addParam('allowfullscreen','true');
so.addVariable('height','260');
so.addVariable('width','620');
so.addVariable('file','http://www.site.com/video/SUBJECT_playlist.php');
so.addVariable('backcolor','0x000000');
so.addVariable('frontcolor','0xffffff');
so.addVariable('lightcolor','0xffffff');
so.addVariable('displayheight','240');
so.addVariable('displaywidth','350');
so.addVariable('overstretch','fit');
so.addVariable('showstop','true');
so.addVariable('showdownload','false');
so.addVariable('repeat','list');
so.write('player');
</script>
Site Structure:
Code:
/home/user/public_html/{protected_by_htaccess}/upload.php
/home/user/public_html/{protected_by_htaccess}/processupload.php
/home/user/public_html/js/swfobject.js
/home/user/public_html/video/mediaplayer.swf
/home/user/public_html/video/SUBJECT_playlist.php
/home/user/public_html/video/SUBJECT/*.flv
/home/user/uploads/
Bookmarks