You are here: Re: Help! Streaming files via PHP get truncated... « All PHP « IT news, forums, messages
Re: Help! Streaming files via PHP get truncated...

Posted by Good Man on 01/27/06 04:37

Good Man <heyho@letsgo.com> wrote in
news:Xns9757D68E58DABsonicyouth@216.196.97.131:


> My problem is that my downloads are always "completing" too soon, and
> always around 1.6 -> 1.9 MB.

hey, guess who JUST read the readfile(); page in the manual? ;)

Down in the comments section are the following posts... I've posted them
here in case anyone is trying to solve this problem in the future and
stumbled across this thread (hello future! do you have flying cars?)


COMMENTS:
( http://ca.php.net/manual/en/function.readfile.php )

flobee at gmail dot com
06-May-2005 02:17
regarding php5:
i found out that there is already a disscussion @php-dev about readfile
() and fpassthru() where only exactly 2 MB will be delivered. so you may
use this on php5 to get lager files

.... which eventually morphed via 'chrisputnam at gmai<snip>' into the
following function, which i have used successfully. thanks chris!


function readfile_chunked($filename,$retbytes=true) {
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
$cnt =0;
// $handle = fopen($filename, 'rb');
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
echo $buffer;
ob_flush();
flush();
if ($retbytes) {
$cnt += strlen($buffer);
}
}
$status = fclose($handle);
if ($retbytes && $status) {
return $cnt; // return num. bytes delivered like readfile() does.
}
return $status;

}

 

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

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