I want to compress some files with gzip in PHP..
It works as it should when the output file is saved into a file.. When the file is opened it looks like this
But not when the output is returned as a string.. Then the opened file looks like this.. Why is tar file showed inside the gzip file?
public function compress(){
if($this->stream){
return gzencode($this->data, 9);
}
else{
$gz = gzopen('test.tar.gz', 'w9');
gzwrite($gz, $this->data);
gzclose($gz);
}
}
headers sent with string output to the browser
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$filename.'"');
I am sure that you looked into http://php.net/manual/en/function.gzcompress.php
make sure that you have php version PHP 4 >= 4.0.1, PHP 5
This function compress the given string using the ZLIB data format.
For details on the ZLIB compression algorithm see the document "» ZLIB Compressed Data Format Specification version 3.3" (RFC 1950).
Parameters
level
encoding
gzencode — Create a gzip compressed string