-
Code's Tags
-
Your Codes
-
Reffers
-
Linked Codes
|
Code:
Short link for Twitter:
HTML:
HTML view:
Copy Source | Copy HTML- <?
- if (!isset($_REQUEST['file_id']) || !((int)$_REQUEST['file_id']) )
- die();
- function browser_info($agent=null) {
- // Declare known browsers to look for
- $known = array('msie', 'firefox', 'safari', 'webkit', 'opera', 'netscape',
- 'konqueror', 'gecko');
-
- // Clean up agent and build regex that matches phrases for known browsers
- // (e.g. "Firefox/2.0" or "MSIE 6.0" (This only matches the major and minor
- // version numbers. E.g. "2.0.0.6" is parsed as simply "2.0"
- $agent = strtolower($agent ? $agent : $_SERVER['HTTP_USER_AGENT']);
- $pattern = '#(?<browser>' . join('|', $known) .
- ')[/ ]+(?<version>[0-9]+(?:\.[0-9]+)?)#';
-
- // Find all phrases (or return empty array if none found)
- if (!preg_match_all($pattern, $agent, $matches)) return array();
-
- // Since some UAs have more than one phrase (e.g Firefox has a Gecko phrase,
- // Opera 7,8 have a MSIE phrase), use the last one found (the right-most one
- // in the UA). That's usually the most correct.
- $i = count($matches['browser'])-1;
- return array($matches['browser'][$i] => $matches['version'][$i]);
- }
- $file_id=(int)$_REQUEST['file_id'];
- require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
- $arr = CFile::MakeFileArray($file_id);
-
- $path = CFile::GetPath($file_id);
- $ext = explode('.', $path);
- $ext = $ext[count($ext)-1];
-
- $description=$arr['description'];
-
- if (mb_strlen($description)>200)
- $description=mb_substr($description, 0,200).'...';
- $pattern = array('"', '/', '\\', '*','?','<','>','|',':');
- for ($i= 0; $i<sizeof($pattern); $i++) {
- $description = mb_ereg_replace($pattern[$i], ' ', $description);
- }
- $ua=browser_info();
- if ($description)
- {
- $fname=mb_convert_encoding($description,"UTF-8", "Windows-1251" ).'.'.$ext;
- if (isset($ua['msie']))
- $fname=$description.'.'.$ext;
- }
- else $fname=basename($arr['tmp_name']);
-
- header('Content-Type: '.$arr['type']);
- header('Content-Length: '.$arr['size']);
-
- header('Content-Disposition: attachment; FILENAME="'.$fname.'"; size="'.$arr['size'].'"');
- echo file_get_contents($arr['tmp_name']);
- ?>
|