gzcompress won't produce a valid zipped file?
Consider this:
$text = "hello";
$text_compressed = gzcompress($text, 6);
$success = file_put_contents('file.gz', $text_compressed);
When i try to open file.gz, i get error开发者_如何学Cs. How can i open file.gz under terminal without calling php? (using gzuncompress works just fine!)
I can't recode every file i did, since that i now have almost a Billion files encoded this way! So if there is a solution... :)
You need to use gzencode()
instead.
Luckily for you, the fix is easy: just write a script that opens each of your files one by one, uses gzuncompress()
to uncompress that file, and then writes that file back out with gzencode()
instead of gzcompress()
, repeating the process for all of the files.
Alternatively (since you said you "didn't want to recode your files"), you could use uncompress
to open the existing files from the command line (instead of gunzip
/zcat
).
As noted on the gzcompress()
manual page:
gzcompress
This is not the same as gzip compression, which includes some header data. See gzencode() for gzip compression.
As said, you don't really have gzipped files. To open your files from a terminal you need the uncompress utility.
精彩评论