function download_headers($downloadname = null, $attachment = null) { if ($this->is_csv()) { header("Content-Type: text/csv; charset=utf-8; header=" . ($this->headerline !== "" ? "present" : "absent")); } else { header("Content-Type: text/plain; charset=utf-8"); } if ($attachment === null) { $attachment = !Mimetype::disposition_inline($this->is_csv() ? "text/csv" : "text/plain"); } if (!$downloadname) { $downloadname = "data" . $this->extension(); } header("Content-Disposition: " . ($attachment ? "attachment" : "inline") . "; filename=" . mime_quote_string($downloadname)); // reduce likelihood of XSS attacks in IE header("X-Content-Type-Options: nosniff"); }
static function multidownload($doc, $downloadname = null, $attachment = null) { global $zlib_output_compression; if (is_array($doc) && count($doc) == 1) { $doc = $doc[0]; $downloadname = null; } if (!$doc || is_object($doc) && isset($doc->size) && $doc->size == 0) { return set_error_html("Empty file."); } if (is_array($doc)) { $z = new ZipDocument($downloadname); foreach ($doc as $d) { $z->add($d); } return $z->download(); } if (!self::has_content($doc) && (!get($doc, "docclass") || !$doc->docclass->load($doc))) { $error_html = "Don’t know how to download."; if (get($doc, "error") && isset($doc->error_html)) { $error_html = $doc->error_html; } else { if (get($doc, "error") && isset($doc->error_text)) { $error_html = htmlspecialchars($doc->error_text); } } return set_error_html($error_html); } // Print paper $doc_mimetype = self::_mimetype($doc); header("Content-Type: " . Mimetype::type($doc_mimetype)); if ($attachment === null) { $attachment = !Mimetype::disposition_inline($doc_mimetype); } if (!$downloadname) { $downloadname = $doc->filename; if (($slash = strrpos($downloadname, "/")) !== false) { $downloadname = substr($downloadname, $slash + 1); } } header("Content-Disposition: " . ($attachment ? "attachment" : "inline") . "; filename=" . mime_quote_string($downloadname)); // reduce likelihood of XSS attacks in IE header("X-Content-Type-Options: nosniff"); if ($filename = self::content_filename($doc)) { self::download_file($filename, get($doc, "no_cache") || get($doc, "no_accel")); } else { $content = self::content($doc); if (!$zlib_output_compression) { header("Content-Length: " . strlen($content)); } echo $content; } return (object) array("error" => false); }