Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- recordings/misc/audio.php 2013-05-06 12:38:58.000000000 -0700
- +++ recordings/misc/audio.php 2013-05-08 16:21:03.000000000 -0700
- @@ -6,49 +6,88 @@
- */
- -if (isset($_GET['recindex'])) {
- -
- - chdir("..");
- - include_once("./includes/bootstrap.php");
- +if (!isset($_GET['recindex'])) {
- + header("HTTP/1.1 400 Bad Request");
- + die("<b>400 No recording index!</b>");
- +}
- - $path = $_SESSION['ari_user']['recfiles'][$_GET['recindex']];
- +chdir("..");
- +include_once("./includes/bootstrap.php");
- - // See if the file exists
- - if (!is_file($path)) { die("<b>404 File not found!</b>"); }
- +$index = (int)$_GET["recindex"];
- +$path = $_SESSION['ari_user']['recfiles'][$index];
- - // Gather relevent info about file
- - $size = filesize($path);
- - $name = basename($path);
- - $extension = strtolower(substr(strrchr($name,"."),1));
- +// See if the file exists
- +if (!is_file($path)) {
- + header("HTTP/1.1 404 Not Found");
- + die("<b>404 File not found!</b>");
- +}
- - // This will set the Content-Type to the appropriate setting for the file
- - $ctype ='';
- - switch( $extension ) {
- +// Gather relevent info about file
- +$size = filesize($path);
- +$name = basename($path);
- +$extension = strtolower(substr(strrchr($name, "."), 1));
- +// This will set the Content-Type to the appropriate setting for the file
- +$ctype = "";
- +switch($extension) {
- case "mp3": $ctype="audio/mpeg"; break;
- case "wav": $ctype="audio/x-wav"; break;
- - case "Wav": $ctype="audio/x-wav"; break;
- - case "WAV": $ctype="audio/x-wav"; break;
- case "gsm": $ctype="audio/x-gsm"; break;
- -
- // not downloadable
- - default: die("<b>404 File not found!</b>"); break ;
- - }
- + default:
- + header("HTTP/1.1 400 Bad Request");
- + die("<b>400 Invalid file type!</b>");
- + break ;
- +}
- - // need to check if file is mislabeled or a liar.
- - $fp=fopen($path, "rb");
- - if ($size && $ctype && $fp) {
- - header("Pragma: public");
- - header("Expires: 0");
- +if (isset($_SERVER['HTTP_RANGE'])) {
- + $partial_content = true;
- + //we're going to ignore the part of the spec that allows two non-contiguous byte ranges to be sent
- + list($range) = explode(",", $_SERVER["HTTP_RANGE"]);
- + $range = explode("-", str_replace("bytes=", "", $range));
- + if (isset($range[0])) {
- + $offset = (int)$range[0];
- + $range_end = isset($range[1]) ? (int)$range[1] : $size - 1;
- + } else {
- + $offset = ($size - 1) - (int)$range[1];
- + $range_end = $size - 1;
- + }
- + $data_size = ($range_end - $offset) + 1;
- + if ($data_size > $size) {
- + $data_size = $size;
- + }
- + if ($data_size <= 0) {
- + header("HTTP/1.1 416 Requested range not satisfiable");
- + die("<b>Requested range not satisfiable!</b>");
- + }
- +} else {
- + $partial_content = false;
- + $offset = 0;
- + $data_size = $size;
- +}
- +$fp = fopen($path, "rb");
- +if ($fp && $size) {
- + fseek($fp, $offset);
- + $buffer = fread($fp, $data_size);
- + $md5_sum = md5($buffer);
- + fclose($fp);
- + if ($partial_content) {
- + error_log("Sending $data_size bytes of partial content: $offset-$range_end/$size (Got $_SERVER[HTTP_RANGE])");
- + header("HTTP/1.1 206 Partial Content");
- + header("Content-Range: bytes $offset-$range_end/$size");
- + header("Accept-Ranges: bytes");
- + }
- + else {
- + error_log("Sending $data_size bytes, full content");
- + header("HTTP/1.1 200 Ok");
- + }
- header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
- - header("Cache-Control: public");
- - header("Content-Description: wav file");
- - header("Content-Type: " . $ctype);
- - header("Content-Disposition: attachment; filename=" . $name);
- - header("Content-Transfer-Encoding: binary");
- - header("Content-length: " . $size);
- + header("Content-type: $ctype");
- + header("Content-Length: $data_size");
- + header("Content-MD5: $md5_sum");
- + header("Connection: close");
- ob_clean();
- - fpassthru($fp);
- - }
- + echo $buffer;
- }
- ?>
- --- recordings/misc/play_page.php 2013-05-06 12:38:58.000000000 -0700
- +++ recordings/misc/play_page.php 2013-05-08 16:25:10.000000000 -0700
- @@ -6,30 +6,25 @@
- */
- chdir("..");
- -include_once("./includes/bootstrap.php");
- -
- -?>
- -
- -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- -<html xmlns="http://www.w3.org/1999/xhtml">
- - <head>
- - <TITLE>ARI</TITLE>
- - <link rel="stylesheet" href="../theme/main.css" type="text/css">
- - <meta http-equiv="content-type" content="text/html; charset=UTF-8">
- - </head>
- - <body>
- -
- -<?php
- -
- - $path = $_SESSION['ari_user']['recfiles'][$_REQUEST['recindex']];
- -
- - if (isset($path)) {
- -
- - echo("<embed width='100%' type='audio/basic' src='audio.php?recindex=" . $_REQUEST['recindex'] . "' width=300, height=25 autoplay=true loop=false></embed><br>");
- - }
- - echo("<script language='javascript'>parent.document.getElementById('pb_load_inprogress').value='false';</script>");
- +require_once("includes/bootstrap.php");
- +$index = (int)$_REQUEST["recindex"];
- +$path = $_SESSION["ari_user"]["recfiles"][$index];
- ?>
- - </body>
- +<!DOCTYPE html>
- +<html>
- + <head>
- + <title>ARI</title>
- + <link rel="stylesheet" href="../theme/main.css" type="text/css"/>
- + <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
- + </head>
- + <body>
- +<?php if (isset($path)):?>
- + <audio src="audio.php?recindex=<?php echo $index?>" autoplay="autoplay" controls="controls">
- + <embed src="audio.php?recindex=<?php echo $index?>" autoplay="true" loop="false"/>
- + </audio>
- +<?php endif;?>
- + <script>if (var ip = parent.document.getElementById('pb_load_inprogress')) {ip.value='false';}</script>
- + </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement