I would like to gzip compress a file on my server using PHP, and without commandLine.
Have successfully written and tried a couple including this How do you create a .gz file using PHP?
But they all include the Full absolute paths, not the relative paths.
The function by both @Simon East AND @Gerben on this page How do you create a .gz file using PHP? all stores full absolute path to entire fileSystem e.g “/var/www/sites/example.com/path/to/my/file.gz” rather than just “my/file.gz”
You wouldn’t know till you attempt extracting it.
Does anyone have an example that would gzip compress file including just it’s relative path?
Have successfully written and tried a couple including this How do you create a .gz file using PHP?
But they all include the Full absolute paths, not the relative paths.
function gzCompressFile($source, $level = 9){
$dest = $source . '.gz';
$mode = 'wb' . $level;
$error = false;
if ($fp_out = gzopen($dest, $mode)) {
if ($fp_in = fopen($source,'rb')) {
while (!feof($fp_in))
gzwrite($fp_out, fread($fp_in, 1024 * 512));
fclose($fp_in);
} else {
$error = true;
}
gzclose($fp_out);
} else {
$error = true;
}
if ($error)
return false;
else
return $dest;
}