Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Code:
Selected Language:
Show Linenumbers:
Short link for Twitter:
HTML:

HTML view:

Copy Source | Copy HTML
  1. <?
  2. if (!isset($_REQUEST['file_id']) || !((int)$_REQUEST['file_id']) )
  3.     die();
  4. function browser_info($agent=null) {
  5.   // Declare known browsers to look for
  6.   $known = array('msie', 'firefox', 'safari', 'webkit', 'opera', 'netscape',
  7.     'konqueror', 'gecko');
  8.  
  9.   // Clean up agent and build regex that matches phrases for known browsers
  10.   // (e.g. "Firefox/2.0" or "MSIE 6.0" (This only matches the major and minor
  11.   // version numbers.  E.g. "2.0.0.6" is parsed as simply "2.0"
  12.   $agent = strtolower($agent ? $agent : $_SERVER['HTTP_USER_AGENT']);
  13.   $pattern = '#(?<browser>' . join('|', $known) .
  14.     ')[/ ]+(?<version>[0-9]+(?:\.[0-9]+)?)#';
  15.  
  16.   // Find all phrases (or return empty array if none found)
  17.   if (!preg_match_all($pattern, $agent, $matches)) return array();
  18.  
  19.   // Since some UAs have more than one phrase (e.g Firefox has a Gecko phrase,
  20.   // Opera 7,8 have a MSIE phrase), use the last one found (the right-most one
  21.   // in the UA).  That's usually the most correct.
  22.   $i = count($matches['browser'])-1;
  23.   return array($matches['browser'][$i] => $matches['version'][$i]);
  24. }
  25. $file_id=(int)$_REQUEST['file_id'];
  26. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
  27. $arr = CFile::MakeFileArray($file_id);
  28.  
  29. $path = CFile::GetPath($file_id);
  30. $ext = explode('.', $path);
  31. $ext = $ext[count($ext)-1];
  32.  
  33. $description=$arr['description'];
  34.  
  35. if (mb_strlen($description)>200)
  36.     $description=mb_substr($description, 0,200).'...';
  37. $pattern = array('"', '/', '\\', '*','?','<','>','|',':');
  38. for ($i= 0; $i<sizeof($pattern); $i++) {
  39.      $description = mb_ereg_replace($pattern[$i], ' ', $description);
  40. }
  41. $ua=browser_info();
  42. if ($description)
  43. {
  44.     $fname=mb_convert_encoding($description,"UTF-8", "Windows-1251" ).'.'.$ext;
  45.         if (isset($ua['msie']))
  46.         $fname=$description.'.'.$ext;
  47. }
  48. else $fname=basename($arr['tmp_name']);
  49.  
  50.     header('Content-Type: '.$arr['type']);
  51.     header('Content-Length: '.$arr['size']);
  52.  
  53.     header('Content-Disposition: attachment; FILENAME="'.$fname.'"; size="'.$arr['size'].'"');
  54.     echo file_get_contents($arr['tmp_name']);
  55. ?>




Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2017