Note Submitter: Michael Keyser
----
I use this to stream and download media files:
<?php
if (isset($_GET['action']) && isset($_GET['file']) && file_exists(stripslashes($_GET['file']))) {
$file = stripslashes($_GET['file']);
$base = basename($file);
$extension = "";
$i = strlen($base);
while (substr($base, $i, 1) != ".") {
$extension = substr($base, $i--, 1) . $extension;
}
switch (strtolower($extension)) {
case "wmv":
case "mpg":
case "mpeg":
case "avi":
case "mov":
include "../mysql_settings.php";
$con = mysql_connect($mysql_host, $mysql_user, $mysql_password) or die(mysql_error());
mysql_select_db($mysql_database) or die(mysql_error());
switch ($_GET['action']) {
case "download":
$query = "INSERT INTO downloads (file,ip_address) VALUES ('". addslashes($file) ."','". $_SERVER['REMOTE_ADDR'] ."')";
mysql_query($query) or die(mysql_error());
mysql_close($con);
$message = "Hello Michael,<br><br>\n"<b>". $file ."</b>" has been downloaded from your website at ". date("g:i:s A - M j, Y") .".<br><br>\nIP Address: <b>". $_SERVER['REMOTE_ADDR'] ."</b>";
email($file ." has been downloaded from your website!", $message);
// tell the browser how big the file is so the user has a percentage complete progress bar
header("Content-Type: ". $extension);
header("Content-Length: ". filesize($file));
header("Content-Disposition: attachment; filename=\"". str_replace(" ", "%20", $base) ."\"");
readfile($file);
break;
case "stream":
$query = "INSERT INTO stream (file,ip_address) VALUES ('". addslashes($file) ."','". $_SERVER['REMOTE_ADDR'] ."')";
mysql_query($query) or die(mysql_error());
mysql_close($con);
$message = "Hello Michael,<br><br>\n"<b>". $file ."</b>" is or has been streamed from your website at ". date("g:i:s A - M j, Y") .".<br><br>\nIP Address: <b>". $_SERVER['REMOTE_ADDR'] ."</b>";
email($file ." is or has been streamed from your website!", $message);
header("location: ". str_replace(" ", "%20", $base));
break;
default:
// action is invalid
break;
}
break;
default:
// invalid file extension
break;
}
}
?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.