note 75091 added to function.header
| From: | MichaelKeyser at osu1 dot php dot net | Date: | Fri, 11 May 2007 19:12:42 +0000 |
| Subject: | note 75091 added to function.header | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-126418@lists.php.net to get a copy of this message | ||
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;
}
}
?>
----
Server IP: 69.39.81.135
Probable Submitter: 67.54.188.109
----
Manual Page -- http://www.php.net/manual/en/function.header.php
Edit -- https://master.php.net/note/edit/75091
Del: integrated -- https://master.php.net/note/delete/75091/integrated
Del: useless -- https://master.php.net/note/delete/75091/useless
Del: bad code -- https://master.php.net/note/delete/75091/bad+code
Del: spam -- https://master.php.net/note/delete/75091/spam
Del: non-english -- https://master.php.net/note/delete/75091/non-english
Del: in docs -- https://master.php.net/note/delete/75091/in+docs
Del: other reasons-- https://master.php.net/note/delete/75091
Reject -- https://master.php.net/note/reject/75091
Search -- https://master.php.net/manage/user-notes.php