cedivad
cedivad

Reputation: 2644

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 errors. 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... :)

Upvotes: 1

Views: 864

Answers (2)

Amber
Amber

Reputation: 526543

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.

Upvotes: 4

Álvaro González
Álvaro González

Reputation: 146390

As said, you don't really have gzipped files. To open your files from a terminal you need the uncompress utility.

Upvotes: 1

Related Questions