When I'm trying to use readfile
with ob_gzhandler
I'm getting in browser:
Content Encoding Error
my code is
function enableCompression()
{
$ok = ob_gzhandler('', PHP_OUTPUT_HANDLER_START);
if ($ok === FALSE) {
return FALSE; // not allowed
}
if (function_exists('ini_set')) {
ini_set('zlib.output_compression', 'Off');
ini_set('zlib.output_compression_level', '6');
}
ob_start('ob_gzhandler', 1);
return TRUE;
}
enableCompression(); //returns TRUE
$file = "pathto/default.png";
$info = @getimagesize($file);
header('Content-type: ' . $info['mime']);
readfile($file);
exit;
When I comment header('Content-type: ' . $info['mime']);
line, I see image data like this in browser
�PNG IHDR��J�TPLTE��ސ�������������ؑ��������vvv�����䀀�� ...."
Am I doing something wrong? Is it possible to compress image data with usage ob_gzhandler?
PS: zlib is installed all is working, other website data is normally outputed. Only compressed image resizer is not working.