All pastes #939982 Raw Edit

dzekas

public php v1 · immutable
·published 2008-03-12 18:21 UTC
rendered paste body
<?phpfunction SendDownloadHeaders($type0, $type1, $filename, $force, $filesize=0) {    $isIE = $isIE6plus = false;    $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];    if (strstr($HTTP_USER_AGENT, 'compatible; MSIE ') !== false &&            strstr($HTTP_USER_AGENT, 'Opera') === false) {        $isIE = true;    }    if (preg_match('/compatible; MSIE ([0-9]+)/', $HTTP_USER_AGENT, $match) &&        ((int)$match[1]) >= 6 && strstr($HTTP_USER_AGENT, 'Opera') === false) {        $isIE6plus = true;    }    $filename = ereg_replace('[\\/:\*\?"<>\|;]', '_', str_replace('&#32;', ' ', $filename));    if ($isIE) {        $filename=rawurlencode($filename);        header ("Pragma: public");        header ("Cache-Control: no-store, max-age=0, no-cache, must-revalidate"); // HTTP/1.1        header ("Cache-Control: post-check=0, pre-check=0", false);        header ("Cache-Control: private");        //set the inline header for IE, we'll add the attachment header later if we need it        header ("Content-Disposition: inline; filename=$filename");    }    if (!$force) {        // Try to show in browser window        header ("Content-Disposition: inline; filename=\"$filename\"");        header ("Content-Type: $type0/$type1; name=\"$filename\"");    } else {        // Try to pop up the "save as" box        // all browsers need the application/octet-stream header for this        header ("Content-Type: application/octet-stream; name=\"$filename\"");        // http://support.microsoft.com/support/kb/articles/Q182/3/15.asp        // Do not have quotes around filename, but that applied to        // "attachment"... does it apply to inline too?        header ("Content-Disposition: attachment; filename=\"$filename\"");        if ($isIE && !$isIE6plus) {            // This combination seems to work mostly.  IE 5.5 SP 1 has            // known issues (see the Microsoft Knowledge Base)            // This works for most types, but doesn't work with Word files            header ("Content-Type: application/download; name=\"$filename\"");            // This is to prevent IE for MIME sniffing and auto open a file in IE            header ("Content-Type: application/force-download; name=\"$filename\"");            // These are spares, just in case.  :-)            //header("Content-Type: $type0/$type1; name=\"$filename\"");            //header("Content-Type: application/x-msdownload; name=\"$filename\"");            //header("Content-Type: application/octet-stream; name=\"$filename\"");        } else if ($isIE) {             // This is to prevent IE for MIME sniffing and auto open a file in IE             header ("Content-Type: application/force-download; name=\"$filename\"");        } else {            // another application/octet-stream forces download for Netscape            header ("Content-Type: application/octet-stream; name=\"$filename\"");        }    }    //send the content-length header if the calling function provides it    if ($filesize > 0) {        header("Content-Length: $filesize");    }}SendDownloadHeaders('application','pdf','license.pdf',true);readfile('./license.pdf');