The video PHP is very similar to the PHP MP3 streaming script. The things that are changed are the following: 1. Database table field names (though they are still very similar). 2. Minor parts of PHP validation. 3. The content type header, from the mp3 format to: header('Content-type: video/mpeg'); The third item is the most important change. If you are using this script for other video file types, use the appropriate content type header. The revised PHP script is shown below: <?php //Validate text input if (! preg_match('/^[-a-z.-@,'s]*$/i',$_GET['ID'])) { die('Invalid name proved, the name may only contain a-z, A-Z, 0-9, "-", "_" and spaces.'); } else $empty=strlen($_GET['ID']); if ($empty==0) { die('The text field cannot be empty'); } else { //the input data is clean, retrieve text data input $ID = $_GET['ID']; } //Connect to MySQL database after sanitizing the data $username = "**********"; $password = "**********"; $hostname = "**********"; $database = "**********"; $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); //select a database to work with $selected = mysql_select_db($database,$dbhandle) or die("Could not select $database"); //Escape variables for use in MySQL $ID = mysql_real_escape_string(stripslashes($ID)); // sending query $result = mysql_query("SELECT `realurl` FROM `videostreaming` WHERE `id`='$ID'") or die(mysql_error()); // store the record of the "example" table into $row $row = mysql_fetch_array( $result ) or die("Invalid query: " . mysql_error()); // Print out the contents of the entry $direction = $row['realurl']; //close the connection $path='http://'.$direction; header('Content-type: video/mpeg'); header('Content-Length: '.filesize($path)); // provide file size header("Expires: -1"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); readfile($path); mysql_close($dbhandle); ?> You can download the script and view the demo.
blog comments powered by Disqus |
|
|
|
|
|
|
|