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:  if (isset($_POST['file'], $_POST['file'][0])) {
       2:   
       3:      if ($idx = strpos($_POST['file'][0], "n")) {
       4:          $bound = substr($_POST['file'][0], 2, $idx-2);
       5:   
       6:          $body  = "MIME-Version: 1.0nContent-type: multipart/form-data; boundary={$bound}nn".
       7:                   $_POST['file'][0];
       8:   
       9:          unset($_POST['file'][0]);
      10:          $f = &$_FILES['file'];
      11:   
      12:          $f['name'] = $f['type'] = $f['tmp_name'] = $f['error'] = $f['size'];
      13:   
      14:          $msg = mailparse_msg_create();
      15:   
      16:          if (mailparse_msg_parse($msg, $body)) {
      17:              $i = 0;
      18:   
      19:              foreach(mailparse_msg_get_structure($msg) as $st) {
      20:   
      21:                  $section = mailparse_msg_get_part($msg, $st);
      22:   
      23:                  $data = mailparse_msg_get_part_data($section);
      24:   
      25:                  if ($data['content-type'] == 'multipart/form-data') {
      26:                      continue; 
      27:                  }
      28:   
      29:                  ob_start();
      30:                  if (mailparse_msg_extract_part($section, $body)) {
      31:                      $tmp = tempnam(sys_get_temp_dir(), 'php');
      32:                      file_put_contents($tmp, ob_get_clean());
      33:   
      34:                      $f['name'][$i] = $data['disposition-filename'];
      35:                      $f['type'][$i] = $data['content-type'];
      36:                      $f['tmp_name'][$i] = $tmp;
      37:                      $f['error'][$i] = 0;
      38:                      $f['size'][$i] = filesize($tmp);
      39:   
      40:                      $i++;
      41:                  } else {
      42:                      ob_end_clean();
      43:                  }
      44:              }
      45:          }
      46:          unset($f);
      47:   
      48:          mailparse_msg_free($msg);
      49:      }
      50:  } 




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