*/
public static function download_file($file, $name, $exit = true)
{
- if (self::is_browser('ie') || self::is_browser('opera') || self::is_browser('safari'))
- {
- $mime = 'application/octetstream';
- }
- else
- {
- $mime = 'application/octet-stream';
- }
-
- header("Content-Type: $mime");
+ header("Content-Type: application/octetstream");
+ header("Content-Type: application/octet-stream");
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Content-Disposition: attachment; filename="' . $name . '"');
header('Content-length: ' . strlen($file));
}
}
- // ###################################################################
- /**
- * Check a browser's user agent against a pre-determined list
- *
- * @param string Browser name
- * @param string The browser's version
- *
- * @param mixed False if there is no match, the version if there is
- */
- public static function is_browser($check, $version = '')
- {
- $useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
- $browser = array();
- $matches = array();
-
- // -------------------------------------------------------------------
- // -- Opera
- // -------------------------------------------------------------------
- # Opera/6.05 (Windows 98; U) [en]
- # Mozilla/4.0 (compatible; MSIE 5.0; Windows 98) Opera 6.0 [en]
- # Mozilla/5.0 (Windows 98; U) Opera 6.0 [en]
- # Mozilla/4.0 (compatible; MSIE, 6.0; Windows 98) Opera 7.0 [en]
- if (preg_match('#opera ([0-9\.]+)#', $useragent, $matches) !== false)
- {
- if (isset($matches[1]))
- {
- $browser['opera'] = $matches[1];
- }
- }
-
- // -------------------------------------------------------------------
- // -- Mac browser
- // -------------------------------------------------------------------
- if (strpos($useragent, 'mac') !== false)
- {
- $browser['mac'] = true;
- }
-
- // -------------------------------------------------------------------
- // -- Internet explorer
- // -------------------------------------------------------------------
- # Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.1; .NET CLR 1.0.2914)
- # Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)
- if (preg_match('#msie ([0-9\.]+)#', $useragent, $matches) !== false && !isset($browser['opera']))
- {
- if (isset($matches[1]))
- {
- $browser['ie'] = $matches[1];
- }
- }
-
- // -------------------------------------------------------------------
- // -- Safari
- // -------------------------------------------------------------------
- # Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.4 (KHTML, like Gecko) Safari/125.9
- if (preg_match('#safari/([0-9\.]+)#', $useragent, $matches) !== false)
- {
- if (isset($matches[1]))
- {
- $browser['safari'] = $matches[1];
- }
- }
-
- // -------------------------------------------------------------------
- // -- Konqueror
- // -------------------------------------------------------------------
- # Mozilla/5.0 (compatible; Konqueror/3)
- # Mozilla/5.0 (compatible; Konqueror/3.1; i686 Linux; 20020628)
- if (preg_match('#konqueror/([0-9\.]+)#', $useragent, $matches) !== false)
- {
- if (isset($matches[1]))
- {
- $browser['konqueror'] = $matches[1];
- }
- }
-
- // -------------------------------------------------------------------
- // -- Mozilla
- // -------------------------------------------------------------------
- # Mozilla/5.001 (windows; U; NT4.0; en-us) Gecko/25250101
- # Mozilla/5.001 (Macintosh; N; PPC; ja) Gecko/25250101 MegaCorpBrowser/1.0 (MegaCorp, Inc.)
- if (preg_match('#gecko/([0-9]+)#', $useragent, $matches) !== false && !isset($browser['safari']))
- {
- if (isset($matches[1]))
- {
- $browser['mozilla'] = $matches[1];
- }
-
- // -------------------------------------------------------------------
- // -- Firefox
- // -------------------------------------------------------------------
- # Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7) Gecko/20040628 Firefox/0.9.1
- # Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4a) Gecko/20030423 Firebird Browser/0.6
- if (preg_match('#(firebird|firefox)( browser)?/([0-9\.]+)#', $useragent, $matches) !== false)
- {
- if (isset($matches[3]))
- {
- $browser['firefox'] = $matches[3];
- }
- }
-
- // -------------------------------------------------------------------
- // -- Netscape
- // -------------------------------------------------------------------
- # Mozilla/5.0 (Macintosh; U; PPC; en-US; rv:0.9.4.1) Gecko/20020318 Netscape6/6.2.2
- if (preg_match('#netscape([0-9].*?)?/([0-9\.]+)#', $useragent, $matches) !== false)
- {
- if (isset($matches[2]))
- {
- $browser['netscape'] = $matches[2];
- }
- }
-
- // -------------------------------------------------------------------
- // -- Camino
- // -------------------------------------------------------------------
- # Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7) Gecko/20040623 Camino/0.8
- if (preg_match('#camino/([0-9\.]+)#', $useragent, $matches) !== false)
- {
- if (isset($matches[1]))
- {
- $browser['camino'] = $matches[1];
- }
- }
- }
-
- if (isset($browser["$check"]))
- {
- if ($version)
- {
- if ($browser["$check"] >= $version)
- {
- return $browser["$check"];
- }
- else
- {
- return false;
- }
- }
- else
- {
- return $browser["$check"];
- }
- }
- else
- {
- return false;
- }
- }
-
// ###################################################################
/**
* Generates a random string of random length (unless otherwise