<?
require_once('../initialize/initialize.php');

//#### Liitet??n luokkakirjastot
require_once(CLASS_CORE_PATH.'dummy.class.php');
require_once(CLASS_CORE_PATH.'session.class.php');
require_once(CLASS_CORE_PATH.'errorhandler.class.php');
require_once(CLASS_CORE_PATH.'usermanager.class.php');
require_once(CLASS_CORE_PATH.'rowtreeparser.class.php');
require_once(CLASS_CORE_PATH.'query.class.php');
require_once(CLASS_CORE_PATH.'rowlist.class.php');
require_once(CLASS_CORE_PATH.'videolist.class.php');
require_once(CLASS_CORE_PATH.'debug.class.php');

$file_id =  $_GET['fid'];

$lFile = new videoList();

$lFile->first('id = '.$_REQUEST['fid']);

$lFile->fetch();

$filename = $lFile->row->id."__".$lFile->getNameAscii();

//full path to dir with video
// $path = '/var/www/html/dev.sitefactory.fi/www/siteTube/www/sitevideo_file/';


$seekat = $_GET["position"];
//$filename = htmlspecialchars($_GET["file"]);
$ext=strrchr($filename, ".");
$file = VIDEOMANAGER_DIR . $filename;
new Debug($file);
if((file_exists($file)) && ($ext==".flv") && (strlen($filename)>2) && (!eregi(basename($_SERVER['PHP_SELF']), $filename)) && (ereg('^[^./][^/]*$', $filename)))
{
        header("Content-Type: video/x-flv");
        if($seekat != 0) {
                print("FLV");
                print(pack('C', 1 ));
                print(pack('C', 1 ));
                print(pack('N', 9 ));
                print(pack('N', 9 ));
        }
        $fh = fopen($file, "rb");
        fseek($fh, $seekat);
        while (!feof($fh)) {
          print (fread($fh, filesize($file))); 
        }
        fclose($fh);
}
	else
{
        print("ERORR: The file does not exist"); }

?>
