Example #1
0
    # Suppress "Pragma: no-cache" header.
} else {
    if (!isset($g_allow_file_cache)) {
        header('Pragma: no-cache');
    }
}
header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time()));
header('Last-Modified: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', $v_date_added));
$t_filename = file_get_display_name($v_filename);
# For Internet Explorer 8 as per http://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
# Don't let IE second guess our content-type!
header('X-Content-Type-Options: nosniff');
http_content_disposition_header($t_filename, $f_show_inline);
header('Content-Length: ' . $v_filesize);
# If finfo is available (always true for PHP >= 5.3.0) we can use it to determine the MIME type of files
$finfo = finfo_get_if_available();
$t_content_type = $v_file_type;
$t_content_type_override = file_get_content_type_override($t_filename);
# dump file content to the connection.
switch (config_get('file_upload_method')) {
    case DISK:
        $t_local_disk_file = file_normalize_attachment_path($v_diskfile, $t_project_id);
        if (file_exists($t_local_disk_file)) {
            if ($finfo) {
                $t_file_info_type = $finfo->file($t_local_disk_file);
                if ($t_file_info_type !== false) {
                    $t_content_type = $t_file_info_type;
                }
            }
            if ($t_content_type_override) {
                $t_content_type = $t_content_type_override;
Example #2
0
/**
 * Include the contents of a file as output.
 * @param string File name
 * @param string Plugin basename
 */
function plugin_file_include($p_filename, $p_basename = null)
{
    global $g_plugin_mime_types;
    if (is_null($p_basename)) {
        $t_current = plugin_get_current();
    } else {
        $t_current = $p_basename;
    }
    $t_file_path = plugin_file_path($p_filename, $t_current);
    if (false === $t_file_path) {
        trigger_error(ERROR_GENERIC, ERROR);
    }
    $t_content_type = '';
    $finfo = finfo_get_if_available();
    if ($finfo) {
        $t_file_info_type = $finfo->file($t_file_path);
        if ($t_file_info_type !== false) {
            $t_content_type = $t_file_info_type;
        }
    }
    // allow overriding the content type for specific text and image extensions
    // see bug #13193 for details
    if (strpos($t_content_type, 'text/') === 0 || strpos($t_content_type, 'image/') === 0) {
        $t_extension = pathinfo($t_file_path, PATHINFO_EXTENSION);
        if ($t_extension && array_key_exists($t_extension, $g_plugin_mime_types)) {
            $t_content_type = $g_plugin_mime_types[$t_extension];
        }
    }
    if ($t_content_type) {
        header('Content-Type: ' . $t_content_type);
    }
    readfile($t_file_path);
}