Page 1 of 1

Large Files corrupted after download

Posted: 30 Dec 2011, 14:39
by yousinghd
I'm using Phocadownload 2.1.4 on Joomla 1.7.3
I hosting files from 150mb - 300mb each and whenever (everytime) a user download the file gets corrupted.
I even tried myself and all files are corrupted after after download has finished.

I then remove the .htaccess and using direct URL and the file is working ok.
Then tried again downloading the file (without .htaccess) using phocadownload and again it is corrupted.

I have no idea how to fix this.

I have tried smaller files a 1-5mb, it works fine with phocadownload.

Please help!! :cry: :cry:

Re: Large Files corrupted after download

Posted: 30 Dec 2011, 15:57
by SonRiab
Seems to be a problem not related to Phoca Download! For me it works with a large file (Ubuntu iso image/Phoca Download 2.1.4/Joomla 1.7.3/PHP 5.3.2)! Maybe it is a php problem!?

Re: Large Files corrupted after download

Posted: 30 Dec 2011, 16:35
by yousinghd
Initially I thought the same thing.
However I installed jdownloads and tested with the same file in the same folder with .htaccess enabled and it and works fine.
Maybe I will do a backup and reinstall phocadownload see if it will fix the problem.

Re: Large Files corrupted after download

Posted: 30 Dec 2011, 16:40
by SonRiab
Could you provide a sample link? (Directly and a PD link if possible!)
And maybe you can check if any errors are logged!?

Re: Large Files corrupted after download

Posted: 31 Dec 2011, 20:21
by yousinghd
I'm not very good with php coding, however reading through and old post on PDF corrupt on download and performing a few trial & error.
I commented out the if statements in the HTTP RANGE coding in phocadownload.php in the helper folder.
Downloaded again all my files and all are working ok now. I really don't understand the coding and logic behind all this or if there are any future problems by commenting out the if statements. For now I am just happy the downloads are working.

// 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;
// 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'])) {
// 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);
} */

}
header("Content-Length: ". $resultLenght);
header("Content-Range: bytes " . $resultRange . '/' . $fileSize);

header("Content-Type: " . (string)$mimeType);
header('Content-Disposition: attachment; filename="'.$fileWithoutPath.'"');
header("Content-Transfer-Encoding: binary\n");

Re: Large Files corrupted after download

Posted: 01 Jan 2012, 17:21
by SonRiab
I am sure the problem is that the filesize function is not working correctly! Maybe the folder is not accessible or some other permission problems!? (It is possible that some errors are logged to the log-file of your server!) The commented code is working correctly! I have tested this code many days before I send it to Jan! (^_^) The commented code is needed to support the possibility of resume a paused download without the need of downloading the whole file again!

Re: Large Files corrupted after download

Posted: 02 Jan 2012, 12:52
by yousinghd
Unfortunately still doesn't work, now I am getting different error, the file is 186MB but finish download at 50-70mb.. like you said cannot resume either.
I have restored the codes.
Check the webserver error log, nothing reported. :(

Here is the file I made public through PD.
http://www.yousinghd.com/index.php?opti ... -v&lang=en

and the direct link is
http://www.yousinghd.com/phocadownload/ ... n%20Vy.mkv

Re: Large Files corrupted after download

Posted: 02 Jan 2012, 15:52
by SonRiab
Hmm the file could not be found when downloading with PD. (o_O)
Anyway! Could you please create a file called test.php with the following content:

Code: Select all

<?php
function customError($errno, $errstr)
{
    echo "<b>Error:</b> [$errno] $errstr<br />";
    echo "Ending Script";
    die();
}

set_error_handler("customError");

$fileSize = filesize("./phocadownload/Tuyet Trang San Ga - Trinh Tuan Vy.mkv");
$httpRange = 0;
$newFileSize = $fileSize - 1;
$resultLenght = (string)$fileSize;
$resultRange = "0-".$newFileSize;
if(isset($_SERVER['HTTP_RANGE']) && preg_match('%^bytes=\d*\-\d*$%', $_SERVER['HTTP_RANGE'])) {
	list($a, $httpRange) = explode('=', $_SERVER['HTTP_RANGE']);
	$httpRange = explode('-', $httpRange);
	if(!empty($httpRange[0]) || !empty($httpRange[1])) {
		$resultLenght = $fileSize - $httpRange[0] - $httpRange[1];
		header("HTTP/1.1 206 Partial Content");
		if(empty($httpRange[0]))
			$resultRange = $resultLenght.'-'.$newFileSize;
		elseif(empty($httpRange[1]))
			$resultRange = $httpRange[0].'-'.$newFileSize;
		else
			$resultRange = $httpRange[0] . '-' . $httpRange[1];
	}
}
echo "Content-Length: ". $resultLenght . "<br />";
echo "Content-Range: bytes " . $resultRange . '/' . $fileSize . "<br />";
?>
Upload it to your joomla root directory and open the file in a browser! What is the result?