0

I have code to read json file send to me via method=PUT (file.php)

<?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 );
?>

but I want as well read .gz version of above file i.e 192.168.1.20/example.json.gz

I tried to handle this like below:

<?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 );

?>

but in wireshark I got :

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

#

I would like to read this .gz file and save it. But it would be great If I could read gz file and fwrite it to other file like it happend for 1st example (myPut.json)

It looks like I have some issue with 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
ekhumoro
  • 115,249
  • 20
  • 229
  • 336
Pretbc
  • 11
  • 4
  • 1
    close `)` in `while` : `while ( ! feof( $gz_file ) {` – Mykyta Dudariev Nov 08 '17 at 14:21
  • OK I add ' )' but still I got Internal Server error / But I see event.json.gz file but size of gz file is 0 ( due to 500 erro I think) – Pretbc Nov 08 '17 at 14:29
  • Issue resolved - It seems that gzopen doesnt work with php://input so I have to save file first with fopen and after that I read file from HDD and remove - long workaround but works – Pretbc Nov 10 '17 at 07:55

0 Answers0