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
if (isset($_POST['file'], $_POST['file'][ 0])) {
    if ($idx = strpos($_POST['file'][ 0], "n")) {
        $bound = substr($_POST['file'][ 0], 2, $idx-2);
        $body = "MIME-Version: 1.0nContent-type: multipart/form-data; boundary={$bound}nn".
                 $_POST['file'][ 0];
        unset($_POST['file'][ 0]);
        $f = &$_FILES['file'];
        $f['name'] = $f['type'] = $f['tmp_name'] = $f['error'] = $f['size'];
        $msg = mailparse_msg_create();
        if (mailparse_msg_parse($msg, $body)) {
            $i =  0;
            foreach(mailparse_msg_get_structure($msg) as $st) {
                $section = mailparse_msg_get_part($msg, $st);
                $data = mailparse_msg_get_part_data($section);
                if ($data['content-type'] == 'multipart/form-data') {
                    continue;
                }
                ob_start();
                if (mailparse_msg_extract_part($section, $body)) {
                    $tmp = tempnam(sys_get_temp_dir(), 'php');
                    file_put_contents($tmp, ob_get_clean());
                    $f['name'][$i] = $data['disposition-filename'];
                    $f['type'][$i] = $data['content-type'];
                    $f['tmp_name'][$i] = $tmp;
                    $f['error'][$i] =  0;
                    $f['size'][$i] = filesize($tmp);
                    $i++;
                } else {
                    ob_end_clean();
                }
            }
        }
        unset($f);
        mailparse_msg_free($msg);
    }
}




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