Download corrupt.Need help
Posted: Tue Jan 22, 2008 4:29 am
Hello,
i dont know what is the problem with this coding.
when i try to download file from other server,the file can be download but it is corrupt.
if i use DAP,the download will stuck at 100%.
if i use flashget,the download is complete but the file is corrupt.
however,if i download a file from local server,everything went fine.
this is my code.
hope anyone can help me.
thanks.
i dont know what is the problem with this coding.
when i try to download file from other server,the file can be download but it is corrupt.
if i use DAP,the download will stuck at 100%.
if i use flashget,the download is complete but the file is corrupt.
however,if i download a file from local server,everything went fine.
this is my code.
hope anyone can help me.
thanks.
Code: Select all
<?php
function DownloadFile($File)
{
$FileName = basename($File);
$FileExt = strtolower(substr(strrchr($FileName,"."),1));
switch($FileExt)
{
case "exe":
$ctype = "application/octet-stream";
break;
case "zip":
$ctype = "application/zip";
break;
case "mp3":
$ctype = "audio/mpeg";
break;
case "mpg":
$ctype = "video/mpeg";
break;
case "avi":
$ctype = "video/x-msvideo";
break;
case "wmv":
$ctype = "video/x-ms-wmv";
break;
default:
$ctype="application/force-download";
}
header("Cache-Control:");
header("Cache-Control: public");
header("Content-Type: $ctype");
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
{
// IE Bug workaround
$IEFileName = preg_replace('/\./', '%2e', $FileName, substr_count($FileName, '.') - 1);
header("Content-Disposition: attachment; filename=\"$IEFileName\"");
}
else
{
header("Content-Disposition: attachment; filename=\"$FileName\"");
}
header("Accept-Ranges: bytes");
$FileSize = 4653240;
// If http_range is sent by browser (or download manager)
if(isset($_SERVER['HTTP_RANGE']))
{
list($a, $Range) = explode("=",$_SERVER['HTTP_RANGE']);
// If yes, download missing part
str_replace($Range, "-", $Range);
$FileSize2 = $FileSize-1;
$new_length = $FileSize2-$Range;
header("HTTP/1.1 206 Partial Content");
header("Content-Length: $new_length");
header("Content-Range: bytes $Range$FileSize2/$FileSize");
}
else
{
$FileSize2 = $FileSize-1;
header("Content-Range: bytes 0-$FileSize2/$FileSize");
header("Content-Length: ".$FileSize);
}
// Open the file
$FP = fopen("$File","rb");
// Seek to start of missing part
fseek($FP,$Range);
while(!feof($FP))
{
// Reset time limit so there's no timeout
set_time_limit(0);
print(fread($FP,1024*8));
flush();
ob_flush();
};
fclose($FP);
exit;
}
// How to use it
DownloadFile("http://files.brothersoft.com/internet/download_managers/FlashGet_54668.exe");
?>