You are here: send file with resume download « PHP Programming Language « IT news, forums, messages
send file with resume download

Posted by Chameleon on 12/16/48 11:57

I want to send a static file, via php to browser with ability to resume
download. This is the code:
--------------------------------------------
function send_file($file, $offset = 0, $offset2 = -1)
{
@$a = filesize($file);
if ($offset2 <= $offset || $offset2 < 1) $offset2 = $a - 1;
if ($offset2 <= $offset || $offset < 0) $offset = 0;

header("Content-Range: bytes $offset-$offset2/$a");
header('Content-Length: ' . ($offset2 - $offset + 1));

@$fp = fopen($file, 'rb') or die("could not open file <b>$file</b>. I
must die ;-(");
fseek($fp, $offset);
$a = 1 + $offset2 - $offset; $b = (int) floor($a / 8192); $a &= 8191;
//HERE!!!

for ($z = 0; $z < $b; $z++) echo @fread($fp, 8192); //HERE!!!
echo @fread($fp, $a);
fclose($fp);
}
---------------------------------------------
It seems to work but not.
With this code, when I click to download with a download manager like
Free Download Manager (with segmented download), it hangs and downloads
nothing.

If I change lines commented "HERE!!!" to:
---------------------------------------------
$a = 1 + $offset2 - $offset; // $b = (int) floor($a / 8192); $a &= 8191;

//for ($z = 0; $z < $b; $z++) echo @fread($fp, 8192);
---------------------------------------------
then all work fine!

The problem is that:
if file is very big (e.g. 100 MBs) then the line
echo @fread($fp, $a);
presses the server memory


Where is the problem?

Thanks

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация