yo, I'm trying to use the 404 error handler to keep all files outside the web root and retrieve them through the script. In general it works, but for whatever reason, the refuses to accept the CSS file and use it for the page
here's the error handler
<?php
header ('Status 200 OK');
define ('MAIN_SCRIPT_LOCATION', '/dir/main/');
define ('ERROR_SCRIPT', MAIN_SCRIPT_LOCATION.'error.inc');
define ('LOCAL_URL', 'http://url/');
define ('FILES_LOCATION', '/dir/files/');
$request = urldecode ($_SERVER['REQUEST_URI']);
if (preg_match ("(\\|/( |\.)*/|/( |\.){1,}$)",$request)) include ERROR_SCRIPT;
$request = explode ('/',$request);
unset ($request[0]);
$last = count($request);
if (empty ($request[$last])) unset ($request[$last]);
$_SERVER['CS_REQUEST'] = array_values ($request);
$file = MAIN_SCRIPT_LOCATION.$request[1].'.inc';
if (file_exists (MAIN_SCRIPT_LOCATION.$request[1].'.inc')) include ($file);
else include ERROR_SCRIPT;
die;
?>
then, here's the script which will retrive the file, which is called after the handler prog finds the user us making a file request (http://url/files/<...>)
<?php
$file = $_SERVER['CS_REQUEST'];
unset ($file[0]);
$file = FILES_LOCATION.join ('/',$file);
if (
!file_exists ($file) or
is_dir ($file) or
!is_readable ($file)
) include ERROR_SCRIPT;
if ($_SERVER['CS_REQUEST'][1] == 'css') header ('Content-Type: text/css; charset=ISO-8859-1');
elseif (
function_exists ('mime_content_type') and
$type = mime_content_type ($file)
) header ('Content-Type: '.$type);
elseif ($type = @getimagesize ($file)) header ('Content-Type: '.$type['mime']);
readfile ($file);
die;
?>