Location: PHPKode > projects > GnomePHP > peec-GnomePHP-b5a360b/gnomephp/mvc/ExternalController.php
<?php
namespace gnomephp\mvc;
/**
 * Allows GnomePHP to have a second public directory for the core itself.
 * 
 * Some features might use the external controller to share common resources.
 * 
 * @author peec
 *
 */
class ExternalController extends CoreController{
	
	protected function fileIsValid($path){
		return !(substr($path, 1) == '/' || strstr($path, '..') || strstr($path, ':'));
	}
	protected function setHeaders($path){
		$file_extension = strtolower(substr(strrchr(realpath($path),"."),1)); 
		$headers = array();
		
        switch ($file_extension) {
            case "css": 
				$ctype="text/css"; 
			break;
			case "css": 
				$ctype="text/javascript"; 
			break;
            case "gif": 
				$ctype="image/gif"; 
			break;
            case "png": 
				$ctype="image/png"; 
			break;
            case "jpe": 
			case "jpeg":
            case "jpg": 
				$ctype="image/jpg"; 
			break;
            default: 
				$ctype="application/force-download";
        }
		$headers[] = "Content-Type: $ctype";
		$headers[] = 'Content-Length: ' . filesize($path);
		$headers[] = 'Content-Disposition: attachment; filename="'.basename($path).'"';
		foreach($headers as $header){
			header($header);
		}
	}
	public function index(){
		if ($this->input->get != null){
		$path = $this->input->get->get('p');

		$Realpath = GNOME_FW_PATH . DIRECTORY_SEPARATOR . 'res' . DIRECTORY_SEPARATOR . 'external' . DIRECTORY_SEPARATOR . $path;
		
		if (!$this->fileIsValid($path) || !file_exists($Realpath)){
			die("File is invalid.");
		}
		
		$this->setHeaders($Realpath);
		
		
		ob_clean();
		flush();
		readfile($Realpath);
		}
		die();
	}

}
Return current item: GnomePHP