Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Follow-up for filename encoding for attachment headers and IE.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jun 26, 2015
1 parent d641046 commit c8b12e1
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions core/src/core/classes/class.HTMLWriter.php
Expand Up @@ -148,6 +148,15 @@ public static function javascriptErrorHandler($errorType, $errorMessage)
die("<script language='javascript'>parent.ajaxplorer.displayMessage('ERROR', '".str_replace("'", "\'", $errorMessage)."');</script>");
}

public static function encodeAttachmentName($name){
if (preg_match('/ MSIE /',$_SERVER['HTTP_USER_AGENT'])
|| preg_match('/ WebKit /',$_SERVER['HTTP_USER_AGENT'])
|| preg_match('/ Trident/',$_SERVER['HTTP_USER_AGENT'])) {
$name = str_replace("+", " ", urlencode(SystemTextEncoding::toUTF8($name)));
}
return $name;
}

/**
* @static
* @param string $attachmentName
Expand All @@ -157,9 +166,7 @@ public static function javascriptErrorHandler($errorType, $errorMessage)
*/
public static function generateAttachmentsHeader(&$attachmentName, $dataSize, $isFile=true, $gzip=false)
{
if (preg_match('/ MSIE /',$_SERVER['HTTP_USER_AGENT']) || preg_match('/ WebKit /',$_SERVER['HTTP_USER_AGENT']) || preg_match(‘/ Trident/’,$_SERVER[‘HTTP_USER_AGENT’])) {
$attachmentName = str_replace("+", " ", urlencode(SystemTextEncoding::toUTF8($attachmentName)));
}
$attachmentName = self::encodeAttachmentName($attachmentName);

header("Content-Type: application/force-download; name=\"".$attachmentName."\"");
header("Content-Transfer-Encoding: binary");
Expand Down Expand Up @@ -197,6 +204,8 @@ public static function generateAttachmentsHeader(&$attachmentName, $dataSize, $i

public static function generateInlineHeaders($attachName, $fileSize, $mimeType)
{
$attachName = self::encodeAttachmentName($attachName);

//Send headers
header("Content-Type: " . $mimeType . "; name=\"" . $attachName . "\"");
header("Content-Disposition: inline; filename=\"" . $attachName . "\"");
Expand Down

0 comments on commit c8b12e1

Please sign in to comment.