diff options
Diffstat (limited to 'includes/file.inc')
-rw-r--r-- | includes/file.inc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/includes/file.inc b/includes/file.inc index 1dd34cbae..588bea086 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -2329,5 +2329,34 @@ function file_directory_temp() { } /** + * Examines a file object and returns appropriate content headers for download. + * + * @param $file + * A file object. + * @return + * An associative array of headers, as expected by file_transfer(). + */ +function file_get_content_headers($file) { + $name = mime_header_encode($file->filename); + $type = mime_header_encode($file->filemime); + // Serve images, text, and flash content for display rather than download. + $inline_types = variable_get('file_inline_types', array('^text/', '^image/', 'flash$')); + $disposition = 'attachment'; + foreach ($inline_types as $inline_type) { + // Exclamation marks are used as delimiters to avoid escaping slashes. + if (preg_match('!' . $inline_type . '!', $file->filemime)) { + $disposition = 'inline'; + } + } + + return array( + 'Content-Type' => $type . '; name="' . $name . '"', + 'Content-Length' => $file->filesize, + 'Content-Disposition' => $disposition . '; filename="' . $name . '"', + 'Cache-Control' => 'private', + ); +} + +/** * @} End of "defgroup file". */ |