<?php

// Modified/fixed flvprovider.php by linFox
// Note changes outlined/explained by comments
// You can remove the commenting when you're done

// Manual configuration is not required, unless you've changed the name or path of the 'flv' folder
// before 0.3.1.9, no config at all was required (because the full path was given in the $_GET['file'] var)
// If you do have custom flv path (ie. not [wiicr_root]/flv/), put the FULL path to the flv folder here,
// including trailing backslash. Otherwise, leave it blank.

$manual_flv_path = "";

// No more config

// The variables $file and $filename in the original file were used interchangebly (incorrectly).
// Seems to have been fixed in latest release, but this file still works fine

// Something that needs to be done if you continue to use this file is changing the error handling. If the IF checks fail, this script return a plaintext response.
// Problem is, this file is ebing called as an flv, remember? So you will never see that error, and the video player will sit there
// doing nothing. The fix: Replace the plaintext error with a small .flv movie with the error text inside it.

// Added if(isset( here to stop a PHP unidentified variable error being output before the video stream, preventing the video from working
// If not set, set to 0 to prevent further errors

$seekat = (isset($_GET['position']))
          ? $_GET['position']
          : 0;

// Add the document_root to the filepath so the file can be found with any path settings/server/installation (in config.pl)

$file = htmlspecialchars($_GET['file']);
$filename = (isset($manual_flv_path) && !empty($manual_flv_path))
            ? $manual_flv_path.$file
            : $_SERVER['DOCUMENT_ROOT'].substr($_SERVER['SCRIPT_NAME'], 0, (-1-strlen(basename($_SERVER['SCRIPT_NAME']))))."/flv/".$file;
$ext = strrchr($filename, ".");

IF (file_exists($filename) && $ext == ".flv" && strlen($filename) > 2 && !eregi(basename($_SERVER['PHP_SELF']), $filename) && ereg('^[^./][^/]*$', $file)) 
{
	header("Content-Type: video/x-flv");

	// Added a size header, for good measure
	header("Content-Length: ".filesize($filename));

	// Added if(isset( here to stop a PHP unidentified variable error being output before the video stream, preventing the video from working
	IF (isset($seekat) && $seekat != 0) 
	{
		print("FLV");
		print(pack('C', 1 ));
		print(pack('C', 1 ));
		print(pack('N', 9 ));
		print(pack('N', 9 ));
	}
	$fh = fopen($filename, "rb");
	fseek($fh, $seekat);
	fpassthru($fh);
	fclose($fh);
}
ELSE
// Fixed a typo here. Check the fourth block of comments for important notes regarding this error system.
print("ERROR: The file does not exist");

?>