Advertisement
miken32

ARI iPhone fix

May 8th, 2013
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.75 KB | None | 0 0
  1. --- recordings/misc/audio.php   2013-05-06 12:38:58.000000000 -0700
  2. +++ recordings/misc/audio.php   2013-05-08 16:21:03.000000000 -0700
  3. @@ -6,49 +6,88 @@
  4.   */
  5.  
  6.  
  7. -if (isset($_GET['recindex'])) {
  8. -
  9. -  chdir("..");
  10. -  include_once("./includes/bootstrap.php");
  11. +if (!isset($_GET['recindex'])) {
  12. +    header("HTTP/1.1 400 Bad Request");
  13. +    die("<b>400 No recording index!</b>");
  14. +}
  15.  
  16. -   $path = $_SESSION['ari_user']['recfiles'][$_GET['recindex']];
  17. +chdir("..");
  18. +include_once("./includes/bootstrap.php");
  19.  
  20. -  // See if the file exists
  21. -  if (!is_file($path)) { die("<b>404 File not found!</b>"); }
  22. +$index = (int)$_GET["recindex"];
  23. +$path = $_SESSION['ari_user']['recfiles'][$index];
  24.  
  25. -  // Gather relevent info about file
  26. -  $size = filesize($path);
  27. -  $name = basename($path);
  28. -  $extension = strtolower(substr(strrchr($name,"."),1));
  29. +// See if the file exists
  30. +if (!is_file($path)) {
  31. +    header("HTTP/1.1 404 Not Found");
  32. +    die("<b>404 File not found!</b>");
  33. +}
  34.  
  35. -  // This will set the Content-Type to the appropriate setting for the file
  36. -  $ctype ='';
  37. -  switch( $extension ) {
  38. +// Gather relevent info about file
  39. +$size = filesize($path);
  40. +$name = basename($path);
  41. +$extension = strtolower(substr(strrchr($name, "."), 1));
  42. +// This will set the Content-Type to the appropriate setting for the file
  43. +$ctype = "";
  44. +switch($extension) {
  45.      case "mp3": $ctype="audio/mpeg"; break;
  46.      case "wav": $ctype="audio/x-wav"; break;
  47. -    case "Wav": $ctype="audio/x-wav"; break;
  48. -    case "WAV": $ctype="audio/x-wav"; break;
  49.      case "gsm": $ctype="audio/x-gsm"; break;
  50. -
  51.      // not downloadable
  52. -    default: die("<b>404 File not found!</b>"); break ;
  53. -  }
  54. +    default:
  55. +        header("HTTP/1.1 400 Bad Request");
  56. +        die("<b>400 Invalid file type!</b>");
  57. +        break ;
  58. +}
  59.  
  60. -  // need to check if file is mislabeled or a liar.
  61. -  $fp=fopen($path, "rb");
  62. -  if ($size && $ctype && $fp) {
  63. -    header("Pragma: public");
  64. -    header("Expires: 0");
  65. +if (isset($_SERVER['HTTP_RANGE'])) {
  66. +    $partial_content = true;
  67. +    //we're going to ignore the part of the spec that allows two non-contiguous byte ranges to be sent
  68. +    list($range) = explode(",", $_SERVER["HTTP_RANGE"]);
  69. +    $range = explode("-", str_replace("bytes=", "", $range));
  70. +    if (isset($range[0])) {
  71. +        $offset = (int)$range[0];
  72. +        $range_end = isset($range[1]) ? (int)$range[1] : $size - 1;
  73. +    } else {
  74. +        $offset = ($size - 1) - (int)$range[1];
  75. +        $range_end = $size - 1;
  76. +    }
  77. +    $data_size = ($range_end - $offset) + 1;
  78. +    if ($data_size > $size) {
  79. +        $data_size = $size;
  80. +    }
  81. +    if ($data_size <= 0) {
  82. +        header("HTTP/1.1 416 Requested range not satisfiable");
  83. +        die("<b>Requested range not satisfiable!</b>");
  84. +    }
  85. +} else {
  86. +    $partial_content = false;
  87. +    $offset = 0;
  88. +    $data_size = $size;
  89. +}
  90. +$fp = fopen($path, "rb");
  91. +if ($fp && $size) {
  92. +    fseek($fp, $offset);
  93. +    $buffer = fread($fp, $data_size);
  94. +    $md5_sum = md5($buffer);
  95. +    fclose($fp);
  96. +    if ($partial_content) {
  97. +       error_log("Sending $data_size bytes of partial content: $offset-$range_end/$size (Got $_SERVER[HTTP_RANGE])");
  98. +        header("HTTP/1.1 206 Partial Content");
  99. +        header("Content-Range: bytes $offset-$range_end/$size");
  100. +        header("Accept-Ranges: bytes");
  101. +    }
  102. +   else {
  103. +       error_log("Sending $data_size bytes, full content");
  104. +       header("HTTP/1.1 200 Ok");
  105. +   }
  106.      header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  107. -    header("Cache-Control: public");
  108. -    header("Content-Description: wav file");
  109. -    header("Content-Type: " . $ctype);
  110. -    header("Content-Disposition: attachment; filename=" . $name);
  111. -    header("Content-Transfer-Encoding: binary");
  112. -    header("Content-length: " . $size);
  113. +    header("Content-type: $ctype");
  114. +    header("Content-Length: $data_size");
  115. +    header("Content-MD5: $md5_sum");
  116. +    header("Connection: close");
  117.      ob_clean();
  118. -    fpassthru($fp);
  119. -  }
  120. +    echo $buffer;
  121.  }
  122.  
  123.  ?>
  124. --- recordings/misc/play_page.php   2013-05-06 12:38:58.000000000 -0700
  125. +++ recordings/misc/play_page.php   2013-05-08 16:25:10.000000000 -0700
  126. @@ -6,30 +6,25 @@
  127.   */
  128.  
  129.  chdir("..");
  130. -include_once("./includes/bootstrap.php");
  131. -
  132. -?>
  133. -
  134. -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  135. -<html xmlns="http://www.w3.org/1999/xhtml">
  136. -  <head>
  137. -    <TITLE>ARI</TITLE>
  138. -    <link rel="stylesheet" href="../theme/main.css" type="text/css">
  139. -    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  140. -  </head>
  141. -  <body>
  142. -
  143. -<?php
  144. -
  145. -  $path = $_SESSION['ari_user']['recfiles'][$_REQUEST['recindex']];
  146. -
  147. -  if (isset($path)) {
  148. -
  149. -    echo("<embed width='100%' type='audio/basic' src='audio.php?recindex=" . $_REQUEST['recindex'] . "' width=300, height=25 autoplay=true loop=false></embed><br>");
  150. -  }
  151. -  echo("<script language='javascript'>parent.document.getElementById('pb_load_inprogress').value='false';</script>");
  152. +require_once("includes/bootstrap.php");
  153. +$index = (int)$_REQUEST["recindex"];
  154. +$path = $_SESSION["ari_user"]["recfiles"][$index];
  155.  ?>
  156.  
  157. -  </body>
  158. +<!DOCTYPE html>
  159. +<html>
  160. +   <head>
  161. +       <title>ARI</title>
  162. +       <link rel="stylesheet" href="../theme/main.css" type="text/css"/>
  163. +       <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
  164. +   </head>
  165. +   <body>
  166. +<?php if (isset($path)):?>
  167. +       <audio src="audio.php?recindex=<?php echo $index?>" autoplay="autoplay" controls="controls">
  168. +           <embed src="audio.php?recindex=<?php echo $index?>" autoplay="true" loop="false"/>
  169. +       </audio>
  170. +<?php endif;?>
  171. +       <script>if (var ip = parent.document.getElementById('pb_load_inprogress')) {ip.value='false';}</script>
  172. +   </body>
  173.  </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement