Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

compression - Unable to read w9 mode compressed gzip file using php

I have the large log files to compress. So, I am using w9 mode for compressing the file.

   $contents = "Containing some logs and its some big size. So, using w9 mode";
   $fname = "test.gz"; 
   $fp = gzopen($fname, "w9"); // Creating gz file.
   gzwrite($fp, $contents); // Writing to file.
   gzclose($fp); // Closing file.

The file is getting compressed and saving in the appropriate location properly. Now, from a different file, I am trying to read the contents and display. I want to read it in array format. So, I am using gzfile function.

if(file_exists($fname)) {
    $lines = gzfile($fname, 1);
    foreach($lines as $fe_key => $fe_line) {
       $lines[$fe_key] = htmlspecialchars($fe_line);
    }
    print_r($lines);
}

Now, the print_r($lines) is giving me an empty array. Please help me, how to fix this problem. Ask me if I need to elaborate a bit more.

Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...