Prior to PHP 5.6 i used code like
<?php
file_get_contents("compress.zlib://php://input");
?>
to read gz-compressed or plain input file. Not it doesn't work.
Simple workaround :
<?php
class gzip_header_filter8 extends php_user_filter {
private $filtered = 0;
public function filter($in, $out, &$consumed, $closing) {
while ($bucket = stream_bucket_make_writeable($in)) {
if($this->filtered == 0) {
$header_len = 8;
$header = substr($bucket->data, 0, 8);
$flags = ord($header[1]);
if($flags & 0x08) {
$header_len = strpos($bucket->data, "\0", 8) + 1;
}
$bucket->data = substr($bucket->data, $header_len);
$this->filtered = $header_len;
}
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
}
}
stream_filter_register('gzip_header_filter8', 'gzip_header_filter8');
$READ_LEN = 64*1024;
$MAX_BUF_LEN = $READ_LEN*1024;
$mode_plain=true;
$src=fopen("php://input","rb"); $magic_number=fread($src,2);
$input="";
if(strlen($magic_number)==2)
if(
(ord($magic_number[0])==31)
&& (ord($magic_number[1])==139)
)
{
$mode_plain=false;
stream_filter_append($src, "gzip_header_filter8", STREAM_FILTER_READ);
stream_filter_append($src, "zlib.inflate", STREAM_FILTER_READ);
}
else
{
$input=$magic_number;
}
$k = 0;
while (!feof($src) && $k <= $MAX_BUF_LEN) {
$inp = fread($src,$READ_LEN);
$k += strlen($inp);
$input.=$inp;
}
echo $input;
fclose($src);
?>