PHP Issues - file uploads
Wotcha folks - have been on a mini mission of late writing a media library for the school's website. Basically I got sick of callouts to install blah codec to play blah video etc, so decided to shunt everything over to FLV thru the browser.
We're using a FreeBSD (with WHM / cPanel) server, and I've got Lame / ffMpeg / FLVTool2 running happily to convert files on the fly and add MetaData. I'm now trying to automate the process so that authorised users can upload their own videos, which the server will then convert and relocate. Now, my PHP skills are limited... I know how to do what I can already do, but beyond that I hit brick walls rapidly. I've got a working system in place already that scans directories for FLVs and builds playlists which then feed into JWPlayer so the whole streaming / playback side is fine. The issue now rests with getting the files on there and converted... in the past this has been done on my workstation and I've then ftp'd them up to the server, but I'm after an easier way.
Here's what I've got at the moment...
The Upload Form:
Code:
<form enctype="multipart/form-data" action="processupload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="104857600" />
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
processupload.php:
Code:
<?php
error_reporting(E_ALL);
ini_set("session.gc_maxlifetime","10800");
$uploaddir = '/INCOMINGPATH/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "File upload was unsuccesful.\n";
}
if (chmod($uploadfile, 0744)) {
echo "CHMOD was succesful. \n";
} else {
echo "CHMOD failed. File is executable. \n";
}
$last_line = system('ffmpeg -i '.$uploadfile.' '.$uploadfile.'.flv', $retval);
$last_line = system('cat '.$uploadfile.'.flv | flvtool2 -U stdin '.$uploadfile.'.flv', $retval);
exec('rm '.$uploadfile.'');
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?>
Now, here are my issues.
1 - I need it to limit the filetypes that can be uploaded to mpg, avi or mov...
2 - The filename of the flv file produced is currently originalfilename.originalextension.flv - I need to lose the original extension...
Any assistance would be immensely appreciated!