PHP - komprimiert statische CSS-Dateien mit GZIP
Also ich habe eine CSS-Datei, style.css. im selben verzeichnis habe ich die bilder / ordner. Wie kann ich ein Skript erstellen, das style.css komprimiert, aber aus einem anderen Ordner?
Jetzt habe ich das:
<?php
if(isset($_GET['css'])) $file = array('url' => htmlspecialchars($_GET['css']), 'type' => 'text/css');
if(isset($_GET['js'])) $file = array('url' => htmlspecialchars($_GET['js']), 'type' => 'application/javascript');
if(!isset($file)) exit();
header('Content-type: '.$file['type']);
header('Cache-Control: max-age='.(60*60*6).', must-revalidate');
// whitespace+comment removal, in case gzip is off
function compress($buffer){
global $file;
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
$buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), ' ', $buffer);
return $buffer;
}
if(extension_loaded('zlib'))
if(substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler");
else ob_start("compress");
include($file['url']);
ob_end_flush();
?>
und benutze es in etwa so:
<style type="text/css">
@import "http://mysite.com/lib/c.php?css=../style.css";
</style>
alles ist in Ordnung, außer dass der Pfad zu den Bildern in der CSS-Datei nicht mehr funktioniert. Ich denke, es liegt daran, dass (images / bg.jpg) zu (../images/bg.jpg)@ wir
Kann ich das Problem beheben, ohne mein c.php-Skript in dasselbe Verzeichnis wie das Stylesheet verschieben zu müssen?