Hello again,
so I can´t find any limitations at my server.
I asked the support from the down-them-all-company.
This support answered that at your phoca download there is a bug with HTTP range.
If you download a file normally with the browser or other tools like wget and cut the download and resume it later
then the file is corrupt too.
I got a patch from the team of down-them-all for you.
Please read it carefully and give me a feedback.
Thank you very much!
Regards,
Kristin
Here the ranges-file:
Fix Request Range handling:
This patch might be correct, but is fully untested.
If you want to use this, then you must verify it actually works!
Code donated to the public domain. Do whatever you want with it.
diff --git a/phocadownload.orig.php b/phocadownload.php
index 2cf8845..14028da 100755
--- a/phocadownload.orig.php
+++ b/phocadownload.php
@@ -145,64 +145,51 @@ class PhocaDownloadHelperFront
header("Content-Description: File Transfer");
header("Expires: Sat, 30 Dec 1990 07:07:07 GMT");
header("Accept-Ranges: bytes");
-
-
- // HTTP Range
- /* $httpRange = 0;
- if(isset($_SERVER['HTTP_RANGE'])) {
- list($a, $httpRange) = explode('=', $_SERVER['HTTP_RANGE']);
- str_replace($httpRange, '-', $httpRange);
- $newFileSize = $fileSize - 1;
- $newFileSizeHR = $fileSize - $httpRange;
- header("HTTP/1.1 206 Partial Content");
- header("Content-Length: ".(string)$newFileSizeHR);
- header("Content-Range: bytes ".$httpRange . $newFileSize .'/'. $fileSize);
- } else {
- $newFileSize = $fileSize - 1;
- header("Content-Length: ".(string)$fileSize);
- header("Content-Range: bytes 0-".$newFileSize . '/'.$fileSize);
- }
- header("Content-Type: " . (string)$mimeType);
- header('Content-Disposition: attachment; filename="'.$fileWithoutPath.'"');
- header("Content-Transfer-Encoding: binary\n");*/
+ $fp = @fopen($absOrRelFile, 'rb');
+
// Modified by Rene
// HTTP Range - see RFC2616 for more informations (
http://www.ietf.org/rfc/rfc2616.txt)
- $httpRange = 0;
$newFileSize = $fileSize - 1;
// Default values! Will be overridden if a valid range header field was detected!
- $resultLenght = (string)$fileSize;
- $resultRange = "0-".$newFileSize;
+ $rangeStart = 0;
+ $rangeEnd = 0;
+ $resultLength = $fileSize;
// We support requests for a single range only.
// So we check if we have a range field. If yes ensure that it is a valid one.
// If it is not valid we ignore it and sending the whole file.
- if(isset($_SERVER['HTTP_RANGE']) && preg_match('%^bytes=\d*\-\d*$%', $_SERVER['HTTP_RANGE'])) {
+ if ($fp && isset($_SERVER['HTTP_RANGE']) && preg_match('%^bytes=\d*\-\d*$%', $_SERVER['HTTP_RANGE'])) {
// Let's take the right side
list($a, $httpRange) = explode('=', $_SERVER['HTTP_RANGE']);
// and get the two values (as strings!)
$httpRange = explode('-', $httpRange);
// Check if we have values! If not we have nothing to do!
- if(!empty($httpRange[0]) || !empty($httpRange[1])) {
- // We need the new content length ...
- $resultLenght = $fileSize - $httpRange[0] - $httpRange[1];
- // ... and we can add the 206 Status.
- header("HTTP/1.1 206 Partial Content");
- // Now we need the content-range, so we have to build it depending on the given range!
- // ex.: -500 -> the last 500 bytes
- if(empty($httpRange[0]))
- $resultRange = $resultLenght.'-'.$newFileSize;
- // ex.: 500- -> from 500 bytes to filesize
- elseif(empty($httpRange[1]))
- $resultRange = $httpRange[0].'-'.$newFileSize;
- // ex.: 500-1000 -> from 500 to 1000 bytes
- else
- $resultRange = $httpRange[0] . '-' . $httpRange[1];
- //header("Content-Range: bytes ".$httpRange . $newFileSize .'/'. $fileSize);
+ if (sizeof($httpRange) == 2) {
+ // Explictly convert to int
+ $rangeStart = intval($httpRange[0]);
+ $rangeEnd = intval($httpRange[1]); // Allowed to be empty == 0
+ if (($rangeStart || $rangeEnd) // something actually set?
+ && $rangeStart < $fileSize // must be smaller
+ && $rangeEnd < $fileSize // must be smaller
+ && (!$rangeEnd || $rangeEnd > $rangeStart) // end > start, if end is set
+ ) {
+ header("HTTP/1.1 206 Partial Content");
+ if (!$rangeEnd) {
+ $resultLength = $fileSize - $rangeStart;
+ $range = $rangeStart . "-" . ($fileSize - 1) . "/" . $fileSize;
+ } else {
+ $resultLength = ($rangeEnd - $rangeStart + 1);
+ $range = $rangeStart . "-" . $rangeEnd . "/" . $fileSize;
+ }
+ header("Content-Range: bytes " . $range);
+ } else {
+ // Didn't validate: kill
+ $rangeStart = 0;
+ $rangeEnd = 0;
+ }
}
}
- header("Content-Length: ". $resultLenght);
- header("Content-Range: bytes " . $resultRange . '/' . $fileSize);
-
+ header("Content-Length: ". $resultLength);
header("Content-Type: " . (string)$mimeType);
header('Content-Disposition: attachment; filename="'.$fileWithoutPath.'"');
header("Content-Transfer-Encoding: binary\n");
@@ -211,13 +198,25 @@ class PhocaDownloadHelperFront
// Try to deliver in chunks
@set_time_limit(0);
- $fp = @fopen($absOrRelFile, 'rb');
if ($fp !== false) {
- while (!feof($fp)) {
- echo fread($fp, 8192);
+ if ($rangeStart) {
+ // Need to pass only part of the file, starting at $rangeStart
+ fseek($fp, $rangeStart, SEEK_SET);
+ }
+ // If $rangeEnd is open ended (0, whole file from $rangeStart) try fpassthru,
+ // else send in small chunks
+ if ($rangeEnd || @!fpassthru($fp)) {
+ while ($resultLength > 0 && !feof($fp)) {
+ // 4 * 1460 (default MSS with ethernet 1500 MTU)
+ // This is optimized for network packets, not disk access
+ $bytes = min(5840, $resultLength);
+ echo fread($fp, $bytes);
+ $resultLength = $resultLength - $bytes;
+ }
}
fclose($fp);
} else {
+ // Ranges are disabled at this point and were never set up
@readfile($absOrRelFile);
}
flush();