if ($dispo == "inline" and !in_array($ext, $inline_extensions)) { $dispo = "attachment"; } $modified = filemtime($row_filename); $etag = '"' . md5($row_filename . $modified) . '"'; header("Last-Modified: " . gmdate("D, d M Y H:i:s", $modified) . " GMT"); header("ETag: {$etag}"); if (!empty($_SERVER["HTTP_IF_NONE_MATCH"]) and $etag == stripslashes($_SERVER["HTTP_IF_NONE_MATCH"]) and !DEBUG) { header("HTTP/1.0 304 Not Modified"); exit; } $resize = false; if (isset($_REQUEST["image_width"]) or isset($_REQUEST["image_height"])) { $resize = true; } if (!$resize and $result = validate::checkvirus($row_filename)) { sys_error("Virus scanner: " . $result, "403 Forbidden"); } else { if ($resize) { $row_filename = _download_resize($row_filename); } _download_file($row_filename, $filename, $dispo); } function _download_file($row_filename, $filename, $dispo) { if ($fp = fopen($row_filename, "rb")) { if (strpos($_SERVER["HTTP_USER_AGENT"], "MSIE")) { $filename = rawurlencode($filename); } sys_log_stat("downloads", 1); header("Expires: " . gmdate("D, d M Y H:i:s", NOW) . " GMT");
static function displayfile($table, $filename, $index = false, $limit = true) { $size = @filesize($filename); $ext = self::getfileext($filename); if ($ext == basename($filename)) { $ext = self::basename($filename); } $txt_files = array("ldif", "log", "css", "csv", "eml", "rfc822", "ini", "reg", "tsv", "txt", "ics", "vcf", "lang"); $code_files = array("bas", "bat", "c", "cmd", "cpp", "csh", "inf", "sh", "vb", "vbe", "xml", "java", "js", "pas", "php", "pl", "vbs", "vcs", "wsh", "tpl", "sql"); $bin_files = array("doc", "docx", "xls", "xlsx", "ppt", "pptx", "tar", "zip", "gz", "tgz", "pdf", "mp3", "odt", "sxw", "ods", "sxc", "odp", "sxi", "jpg", "jpeg", "tif", "url"); $html_files = array("htm", "html"); $return = ""; $return_html = ""; $cid = str_replace("simple_", "", $table) . "_" . sha1($filename . $size . @filemtime($filename)); if ($return = sys_cache_get($cid)) { if (!$index and $limit and strlen($return) > FILE_TEXT_LIMIT) { $return = substr($return, 0, FILE_TEXT_LIMIT) . " ..."; } return trim($return); } $type = ""; if (in_array($ext, $txt_files)) { $type = "text"; } else { if (in_array($ext, $code_files)) { $type = "code"; } else { if (in_array($ext, $html_files)) { $type = "html"; } else { if (in_array($ext, $bin_files)) { $type = "bin"; } } } } if ($type != "" and file_exists($filename)) { if ($type == "bin") { if (filesize($filename) != 0) { if (!sys_strbegins($filename, SIMPLE_STORE . "/") and $result = validate::checkvirus($filename)) { $return = "ERROR Virus scanner: " . $result; } else { $return = trim(self::preview_bin($filename, $ext)); } } } else { $return = trim(file_get_contents($filename, false, null, -1, $limit ? FILE_TEXT_LIMIT : 131072)); } if ($return != "") { if ($index) { $rlimit = INDEX_LIMIT; } else { $rlimit = FILE_TEXT_LIMIT; } if ($limit and strlen($return) > $rlimit) { $return = substr($return, 0, $rlimit) . " ..."; } if (!self::detect_utf($return)) { $return = utf8_encode($return); } if ($type == "html") { $return_html = substr($return, 0, strrpos($return, ">")); } else { if ($type != "code") { $return_html = nl2br(strip_tags($return, "<a><b><i>")); } else { $return_html = self::highlight_string($return); } } } } if ($return_html == "") { $return_html = " "; } if (!sys_strbegins($return, "ERROR ")) { sys_cache_set($cid, $return_html, FILE_TEXT_CACHE); if ($index) { return $return; } else { return trim($return_html); } } else { sys_log_message_log("php-fail", "displayfile: " . $return); } if ($index) { return ""; } return sprintf("{t}Cannot create preview for %s{/t}.", $ext); }