All pastes #223179 Raw Edit

Unnamed

public text v1 · immutable
#223179 ·published 2006-10-26 20:02 UTC
rendered paste body
class Downloads_model extends Model {

	function Downloads_model()
	{
		parent::Model();
		$this->obj =& get_instance();
	}


	
	function headers($file_name)
	{
		$agent = $_SERVER["HTTP_USER_AGENT"];
		if( is_int(strpos($agent, "MSIE")) )
		{
			# Remove reserved chars: :\/*?"<>|
			$fn = preg_replace('/[:\\x5c\\/*?"<>|]/', '_', $file_name);
			# Non-standard URL encoding:
			$data = "Content-Disposition: attachment; filename=" . rawurlencode($fn);
			return $data;
		
		} else if( is_int(strpos($agent, "Gecko")) ){
			# RFC 2231:
			$data = "Content-Disposition: attachment; filename*=UTF-8''" . rawurlencode($file_name);
			return $data;
		
		} else if( is_int(strpos($agent, "Opera")) ) {
			# Remove reserved chars: :\/*{?
			$fn = preg_replace('/[:\\x5c\\/{?]/', '_', $file_name);
			# RFC 2231:
			$data = "Content-Disposition: attachment; filename*=UTF-8''" . rawurlencode($fn);
			return $data;
		
		} else {
			# RFC 2616 ASCII-only encoding:
			$fn = mb_convert_encoding($file_name, "US-ASCII", "UTF-8");
			$fn = (string) str_replace("\\", "\\\\", $fn);
			$fn = (string) str_replace("\"", "\\\"", $fn);
			$data = "Content-Disposition: attachment; filename=\"$fn\"";
			return $data;
		}
	}
}