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.'"');