使用PHP读取/写入.gz文件(method =“PUT”)

时间:2017-11-08 14:10:28

标签: php apache gz

我有通过json(file.php)发送给我的method=PUT文件的代码

<?php
$putdata = fopen( "php://input", "r" );  // to read/write json
$fp = fopen( "myPut.json", "w" );
while ( $data = fread( $putdata, 1024 ) )
     fwrite( $fp, $data );
fclose( $fp );
fclose( $putdata );
?>

但我想阅读上述文件的.gz版本,即192.168.1.20/example.json.gz

我试着像下面这样处理:

<?php

$gz_file = gzopen( "php://input", "rb" );
$fp = fopen( "event.json.gz", "w+b" );
while ( ! feof( $gz_file ) {
  fwrite( $fp, gzread( $gz_file, 2048 ) );
}
fclose( $fp );
gzclose( $putdata );

?>

但是在wireshark中我得到了:

12081 89.736965987 192.168.1.30 192.168.1.20 HTTP 484 PUT /test/file.php HTTP/1.1

12083 89.737075602 192.168.1.20 192.168.1.30 HTTP 251 HTTP/1.0 500 Internal Server Error

我想阅读此.gz文件并保存。但它会很棒如果我能读取gz文件并将其写入其他文件,就像第一个例子中发生的那样(myPut.json)

看起来我对feof / gzread func有一些问题:

[Thu Nov 09 09:34:52.482566 2017] [:error] [pid 14253] [client 192.168.1.65:38302] PHP Warning:  feof() expects parameter 1 to be resource, boolean given in /var/www/html/test/file.php on line 29
[Thu Nov 09 09:34:52.482570 2017] [:error] [pid 14253] [client 192.168.1.65:38302] PHP Warning:  gzread() expects parameter 1 to be resource, boolean given in /var/www/html/test/file.php on line 30
[Thu Nov 09 09:34:52.482575 2017] [:error] [pid 14253] [client 192.168.1.65:38302] PHP Warning:  feof() expects parameter 1 to be resource, boolean given in /var/www/html/test/file.php on line 29
[Thu Nov 09 09:34:52.482579 2017] [:error] [pid 14253] [client 192.168.1.65:38302] PHP Warning:  gzread() expects parameter 1 to be resource, boolean given in /var/www/html/test/file.php on line 30
[Thu Nov 09 09:34:52.482583 2017] [:error] [pid 14253] [client 192.168.1.65:38302] PHP Warning:  feof() expects parameter 1 to be resource, boolean given in /var/www/html/test/file.php on line 29

0 个答案:

没有答案