<?php

include_once($_SERVER['DOCUMENT_ROOT'] . '/includes.php');


$url = explode('/', $_SERVER['REQUEST_URI']);

$no_pic = false;
if(count($url)){
	$url = $url[count($url) - 1];
	$url = explode('?', $url); $url = $url[0];

	$file = $_SERVER['DOCUMENT_ROOT'] . '/UPLOAD/BANNERS/' . $url;
	if(!is_file($file))	$no_pic = true;

}else $no_pic = true;



if($no_pic){
	$w = abs($_GET['w']) ? abs($_GET['w']) : 100;
	$h = abs($_GET['h']) ? abs($_GET['h']) : $w;

	$img2 = imagecreatetruecolor($w, $h);
	$grey = imagecolorallocate($img2, 150, 150, 150);
	imagefilledrectangle($img2, 0, 0, $w, $h, $grey);

	header('Expires: Mon, 23 May 1995 02:00:0 GMT');
	header('Content-type: image/jpeg');
	imagejpeg($img2, null, 100);

}else{
	$type = getimagesize($file);

	if(!abs($_GET['w']) && !abs($_GET['h'])){
		header('Expires: Mon, 23 May 1995 02:00:0 GMT');
		header('Content-type: ' . $type['mime']);
		print file_get_contents($file);
		exit;

	}else{
		if(!isset($_IMG_MIME_TO_FUNCTION[$type['mime']])) $file = $_SERVER['DOCUMENT_ROOT'] . '/UPLOAD/BANNERS/flash.jpg';
		image_output($file, $_GET['w'], $_GET['h'], 1);
	}
}


?>