Page 1 of 2

zip file getting corrupted with download manager

Posted: 10 Dec 2010, 22:40
by javangelo
Hi,

When ever I am trying to download a file using Firefox download manager plugin (downthemall). The zip file being downloaded is getting corrupted and also the download count increases by 5 instead of 1.

This downlaod plugin works perfectly on other sites.

If I dont use download manager and download directly, then the zip gets downloaded perfectly.

Please let me know if there is a solution to this.

Here is the link

http://www.appnimi.com/softwares/pdfunlocker

thanks in advance !!

Re: zip file getting corrupted with download manager

Posted: 12 Dec 2010, 00:38
by Jan
Hi, I have downloaded a file from this site and got no problems ???

The zip: PDF_Unlocker_Setup.zip

includes:
Readme.html
and Setup_PDFUnlocker.exe

See no problem there ???

Anyway Phoca Download only gives info from server to browser, the downloading is working between browser and server, so maybe checking some server settings :idea: :(

Jan

Re: zip file getting corrupted with download manager

Posted: 12 Dec 2010, 09:37
by javangelo
Hi Jan,

The issue I had faced was when I download using DownThemAll plugin of firefox.

Also the other scenario I found can be was when I replace the zip file with a new zip file using ftp. Keeping the name of zip file same.

I am as such not able to upload the file directly using your browser upload.

thanks....

/jav

Re: zip file getting corrupted with download manager

Posted: 14 Dec 2010, 17:41
by Jan
I am as such not able to upload the file directly using your browser upload.
Do you use the single file upload, do you get some error message?

Re: zip file getting corrupted with download manager

Posted: 01 Apr 2012, 17:57
by lime21
Hello,
I got the same problem.
If I download my zip-file with downthemall the zip-file is empty then, although I became 5 MB downloaded.
If I download it with browser, I get the full zip-file.
The zip-file I uploaded with ftp on my server.

What is the solution of this?

Best regards

Kris

Re: zip file getting corrupted with download manager

Posted: 03 Apr 2012, 01:14
by Jan
Hi, check your server settings, if there are no limits, etc. see similar posts.

Jan

Re: zip file getting corrupted with download manager

Posted: 10 Apr 2012, 09:26
by lime21
Hi Jan,
Jan wrote:see similar posts.
so I found e.g. this one:

viewtopic.php?f=31&t=17472

I tried this but it doesn´t work.

I tried to copy my zip-file at the main-directory and then I downloaded it with download-manager. In this case my zip-file is ok! But when I download this zip-file from your component the zip-file is empty.

What have I overseen or are there other helpful solutions?

Greetings, Kris

Re: zip file getting corrupted with download manager

Posted: 19 Apr 2012, 00:32
by Jan
Hi, no idea there, Phoca Download only gives information between server and user's browser which downloads the file, the download is working between browser and server - tested on many sites, so seems like the server settings need to be checked, if there is no limit, etc. which can somehow prevent from downloading the ZIP :-(

Jan

Re: zip file getting corrupted with download manager

Posted: 01 Jun 2012, 20:57
by lime21
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();

Re: zip file getting corrupted with download manager

Posted: 06 Jun 2012, 16:38
by Jan
Hi, I will take a look at it. Thank you for this info.

Jan