|
Posted by just.starting@gmail.com on 01/12/06 23:54
This is the code I am using now, and I am able to download only bytes
with length n*chunk_size where n is a number, like I am unable to get
the last few bytes.
for examle if the filesize is 400 bytes and i use 256 bytes as
chunksize I am getting only 256 bytes and then the connection is being
closed. what is happening here. Is there any problem with the code. BTW
I tried the same code at another machine and it works perfectly OK.
$download_size = filesize($fullpath);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: $contenttype;");
header("Content-Disposition: attachment;
filename=\"".basename($file_name)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$download_size);
while (ob_get_level()) {
ob_end_flush();
}
// start output buffering
if (ob_get_length() === false) {
ob_start();
}
$chunksize = 256; // how many bytes per chunk
$buffer = '';
$handle = fopen($filename, 'r');
if ($handle === false) {
return false;
}
$count = 0;
while (!feof($handle)) {
set_time_limit(0);
echo fread($handle,$chunksize);
ob_flush();
flush();
}
ob_end_flush();
[Back to original message]
|