Location: PHPKode > projects > PhpWebDesk > phpWebDesk/compress_f.php
<?php
//
// phpWebDesk transparent compressor
//

// generation [1] : gzip compression

// catch nasty filenames
if (!file_exists($filename)) { die("Aaaahhhh! That file doesn't exist!");}

// stop forbidden extensions/files (e.g. don't let people go and download php code)
// Remember to include the '.' in the extension, e.g. '.php'.
// You can also use this to stop other files, eg .htaccess or passwords.txt
$forbiddenexts = array(".php", ".inc", ".htaccess", ".htpasswd", "passwords.txt");
foreach($forbiddenexts as $ext2blk) {
if (stristr($filename, $ext2blk)) { die("Noooo! That's a forbidden file. Thought you'd get away with it, did you?");}
}

// what's our file? nab it.
$file = file_get_contents($filename) or die("Cannot access specified file.");

// find actual filename (for header)
$fnamebits = split ('[/\\]', $filename);
// whoops, forgot how to get an array's length. will use this for now.
function arraylen($thearray) {
    foreach($thearray as $thing) {
        $i++;
    }
    return $i;
}
$hfilename = $filename.".gz";

// May put MD5 verification in here later.
// i.e. reads md5 check file and checks we've read it right

// Send headers. Will use application/octet-stream as mimetype.
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=".$hfilename);

// Send compressed file
echo gzcompress($file, 9);
Return current item: PhpWebDesk