by Justin Silverton
Zlib compression has been built into php since version 3 and it can be used to compress the output of your php applications (which can significantly decrease the amount of bandwidth of a page), but what you can also do is compress any file accessible from your webserver.
The code
The following are two functions: compress and uncompress, which can compress and uncompress a specified file.
function uncompress($srcName, $dstName) {
$string = implode(”", gzfile($srcName));
$fp = fopen($dstName, “w”);
fwrite($fp, $string, strlen($string));
fclose($fp);
}
function compress($srcName, $dstName)
{
$fp = fopen($srcName, “r”);
$data = fread ($fp, filesize($srcName));
fclose($fp);
$zp = gzopen($dstName, “w9″);
gzwrite($zp, $data);
gzclose($zp);
}
compress(”test.php”,”test.gz”);
uncompress(”test.gz”,”test2.php”);
Source code can be downloaded here
Description of related zlib functions
No comments:
Post a Comment