This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

WP-Filebase Range handling patch for 0.2.9.36

By: a guest on May 2nd, 2013  |  syntax: Diff  |  size: 1.84 KB  |  views: 44  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Index: classes/Download.php
  2. ===================================================================
  3. --- classes/Download.php        (revision 706775)
  4. +++ classes/Download.php        (working copy)
  5. @@ -416,24 +416,24 @@
  6.                 wp_die(__('Could not read file!', WPFB));
  7.                
  8.         $begin = 0;
  9. -       $end = $size;
  10. +       $end = $size - 1;
  11.  
  12.         $http_range = isset($_SERVER['HTTP_RANGE']) ? $_SERVER['HTTP_RANGE'] : '';
  13.         if(!empty($http_range) && strpos($http_range, 'bytes=') !== false && strpos($http_range, ',') === false) // multi-range not supported (yet)!
  14.         {
  15.                 $range = explode('-', trim(substr($http_range, 6)));
  16.                 $begin = 0 + trim($range[0]);
  17. -               if(!empty($range[1]))
  18. +               if(is_numeric($range[1]))
  19.                         $end = 0 + trim($range[1]);
  20.         } else
  21.                 $http_range = '';
  22.        
  23. -       if($begin > 0 || $end < $size)
  24. +       if($begin > 0 || $end < ($size - 1))
  25.                 header('HTTP/1.0 206 Partial Content');
  26.         else
  27.                 header('HTTP/1.0 200 OK');
  28.                
  29. -       $length = ($end-$begin);
  30. +       $length = ($end - $begin + 1);
  31.         WPFB_Download::AddTraffic($length);
  32.        
  33.        
  34. @@ -447,7 +447,7 @@
  35.         }
  36.         header("Content-Length: " . $length);
  37.         if(!empty($http_range))
  38. -               header("Content-Range: bytes " . $begin . "-" . ($end-1) . "/" . $size);
  39. +               header("Content-Range: bytes " . $begin . "-" . $end . "/" . $size);
  40.        
  41.         // clean up things that are not needed for download
  42.         @session_write_close(); // disable blocking of multiple downloads at the same time
  43. @@ -483,9 +483,9 @@
  44.  
  45.                 $cur = $begin;
  46.                
  47. -               while(!@feof($fh) && $cur < $end && @connection_status() == 0)
  48. +               while(!@feof($fh) && $cur <= $end && @connection_status() == 0)
  49.                 {              
  50. -                       $nbytes = min($buffer_size, $end-$cur);
  51. +                       $nbytes = min($buffer_size, $end - $cur + 1);
  52.                         $ts = microtime(true);
  53.  
  54.                         print @fread($fh, $nbytes);
  55. @@ -534,4 +534,4 @@
  56.         return array('error' => false, 'size' => $size);
  57.  }
  58.  
  59. -}
  60. \ No newline at end of file
  61. +}
clone this paste RAW Paste Data