note 105471 added to function.fread
| From: | randym at osu1 dot php dot net | Date: | Sat, 20 Aug 2011 17:45:56 +0000 |
| Subject: | note 105471 added to function.fread | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-182611@lists.php.net to get a copy of this message | ||
Concerning the UTF-8 problem with downloading Zip files I found that simply adding 3 lines of code
before starting the fread to the buffer for delivery in all browsers solved the problem.
ob_end_clean();
ob_start();
header( 'Content-Type:' );
... see where placed in the function below:
function readfile_chunked( $filename, $retbytes = true ) {
$chunksize = 1 * (1024 * 1024); // how many bytes per chunk
$buffer = '';
$cnt = 0;
$handle = fopen( $filename, 'rb' );
if ( $handle === false ) {
return false;
}
ob_end_clean(); //added to fix ZIP file corruption
ob_start(); //added to fix ZIP file corruption
header( 'Content-Type:' ); //added to fix ZIP file corruption
while ( !feof( $handle ) ) {
$buffer = fread( $handle, $chunksize );
//$buffer = str_replace("","",$buffer);
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;
}
----
Server IP: 192.41.42.26
Probable Submitter: 99.60.149.201
----
Manual Page -- http://www.php.net/manual/en/function.fread.php
Edit -- https://master.php.net/note/edit/105471
Del: integrated -- https://master.php.net/note/delete/105471/integrated
Del: useless -- https://master.php.net/note/delete/105471/useless
Del: bad code -- https://master.php.net/note/delete/105471/bad+code
Del: spam -- https://master.php.net/note/delete/105471/spam
Del: non-english -- https://master.php.net/note/delete/105471/non-english
Del: in docs -- https://master.php.net/note/delete/105471/in+docs
Del: other reasons-- https://master.php.net/note/delete/105471
Reject -- https://master.php.net/note/reject/105471
Search -- https://master.php.net/manage/user-notes.php