background image

header("Last-Modified: " . $last_modified);

// 设置文件类型信息

header($p_type);

header("Content-Length: " . $content_length);

}

define('ABSPATH', dirname(__file__) . '/');

$cache = true;

$cachedir = 'cache/'; //存放 gz 文件的目录,确保可写

if (empty($_SERVER['QUERY_STRING']))

exit();

$gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');

if (empty($gzip))

$cache = false;

$key = array_shift(explode('?', $_SERVER['QUERY_STRING']));

$key = str_replace('../', '', $key);

$filename = ABSPATH . $key;

$symbol = '_';

$rel_path = str_replace(ABSPATH, '', dirname($filename));

$namespace = str_replace('/', $symbol, $rel_path);

$cache_filename = ABSPATH . $cachedir . $namespace . $symbol . basename($filename) .

'.gz'; //生成 gz 文件路径

$ext = array_pop(explode('.', $filename)); //根据后缀判断文件类型信息

$type = "Content-type: text/html"; //默认的文件类型

switch ($ext)

{

case 'css':

$type = "Content-type: text/css";

break;

case 'js':

$type = "Content-type: text/javascript";

break;

case 'gif':