<?php
/*
	DevSaver Web Framework
	Copyright (c) 2002-2018 DevSaver. 
	All rights reserved.
		web:  www.devsaver.com
		mail: support@devsaver.com
*/

if (!defined("STPBase")) {
	die("This file can't be accessed directly!");
}
// dependencies

class CMime {
	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function __construct($file = null) {

		if ($file == null) {
			$file = _LIBPATH  . "include/mime.xml";
		}
		
		//load the xml file
		$tmp = new CConfig($file);
		$this->types = $tmp->data["content-type"];
	}

	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function Set($ext) {
		header("Content-type: " . $this->types[$ext]);
	}

	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function GetByExt($file) {
		//get the file extenstion
		$tmp = explode("." , $file);
		krsort($tmp);
		reset($tmp);

		$ext = $tmp[key($tmp)];

		return $this->types[strtolower($ext)] ? $this->types[strtolower($ext)] : $this->types["unknown"];
	}
	
	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function Filename($file) {
		header('Content-Disposition: attachment; filename="' . str_replace("%20" , " " , $file) . '"');
	}
	
	
	
}
?>