示例#1
0
function get_mime_type($fileOrInline, $inline = false)
{
    /*{{{*/
    $type = false;
    if (!$inline && !file_exists($fileOrInline)) {
        return false;
    }
    if (class_exists('finfo')) {
        $finfo = new finfo(FILEINFO_MIME, "/usr/share/misc/magic");
        $type = $inline ? $finfo->buffer($fileOrInline) : $finfo->file($fileOrInline);
        // Bugfix: PHP erkennt PDF-Dateien leider oft falsch
        if (substr($type, 0, 24) == 'application/octet-stream') {
            $file_header = $inline ? substr($fileOrInline, 0, 100) : file_get_contents($fileOrInline, false, NULL, 0, 100);
            if (substr($file_header, 0, 4) == "%PDF") {
                $type = "application/pdf";
            }
        }
    } else {
        in_shell_execution(true);
        if ($inline && function_exists('proc_open')) {
            $fo = proc_open("file -b --mime-type -", array(0 => array("pipe", "r"), 1 => array("pipe", "w")), $pipes);
            fwrite($pipes[0], $fileOrInline);
            fclose($pipes[0]);
            $type = trim(stream_get_contents($pipes[1]));
            fclose($pipes[1]);
            proc_close($fo);
        } elseif (!$inline && function_exists('popen')) {
            $type = trim(stream_get_contents(popen("file -b --mime-type " . escapeshellarg($fileOrInline), "r")));
        }
        in_shell_execution(false);
    }
    return $type;
}
示例#2
0
}
$query->execute(array(time(), 3600 * 24 * 2, 'drucken.pdf', $final_cache_id));
// Je nach Aktion handeln
$action = $_POST['action'];
if ($action == "Drucken" && $ssh_printing_enabled) {
    // Per SSH an den Drucker übergeben
    if (!user()->ssh) {
        status_message("Für diese Funktion muss ein <a href='index.php?q=acc'>SSH-Zugang konfiguriert</a> sein.");
        gotop("index.php");
    } else {
        $pdf_data = file_get_contents($cache_dir . $final_cache_id);
        in_shell_execution(true);
        $ssh_program = popen("ssh -o PasswordAuthentication=no -i " . escapeshellarg($ssh_printing_privkey_file) . " -a -k -q -x " . escapeshellarg(user()->ssh['account']) . '@' . escapeshellarg($ssh_printing_host) . " lp", "w");
        fwrite($ssh_program, $pdf_data);
        $status = pclose($ssh_program);
        in_shell_execution(false);
        if ($status == 0) {
            status_message("Der Druckauftrag wurde erfolgreich weitergegeben");
            gotop("index.php");
        } else {
            if ($status == 1) {
                status_message("Fehler beim Drucken. Hast Du den Druckernamen richtig eingetippt?");
            } elseif ($status == 255) {
                status_message("Fehler beim Drucken. Hast Du die Anweisungen in der Email befolgt (Schlüssel eingetragen)?");
            }
            gotop("index.php");
        }
    }
} else {
    // PDF herunterladen
    gotop('cache.php?cache_id=' . $final_cache_id);