Development

#1811 (addition of "charset=utf-8" after content-type causes problems for IE and pdf files)

You must first sign up to be able to contribute.

Ticket #1811 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

addition of "charset=utf-8" after content-type causes problems for IE and pdf files

Reported by: Brian.Kendig Assigned to: fabien
Priority: minor Milestone: 1.0.11
Component: view Version: 1.0.2
Keywords: Cc:
Qualification: Unreviewed

Description

I have an action which creates a PDF file on-the-fly, puts its contents into $this->pdf, and passes it to the template which consists only of "<?php echo $pdf ?>". The Content-type is set to "application/pdf" in the view.yml file. This works fine with Firefox, opening the contents of the PDF in a browser window.

But with Internet Explorer 7 it brings up an error dialog instead: "The file you are downloading cannot be opened by the default program. It is either corrupted or it has an incorrect file type. As a security precaution, it is recommended that you cancel the download."

The problem is that Symfony sets the Content-type header to "application/pdf; charset=utf-8". Having "charset" appear here confuses IE. (See "http://www.adobeforums.com/cgi-bin/webx/.3bc37b8a") for another report of this problem.)

I solved the problem by eliminating the template and the view.yml and instead having "echo $pdf" in the action itself. But the charset problem might bite someone else. Technically, I believe it's incorrect to specify a charset encoding for a file that's not text (whose MIME type isn't 'text/*'), so technically I think symfony is doing the wrong thing by adding "charset" indiscriminately to every page it serves (a change which was made in Changeset 1752; see 'http://trac.symfony-project.com/trac/changeset/1752'.)

Here is a patch to sfWebResponse.class.php which will work around the problem in this specific case:

line 238: << if (false === stripos($value, 'charset'))

if (false === stripos($value, 'charset') and false === stripos($value, 'application/pdf'))

... but I don't recommend this patch as a general solution, because it should apply to all binary files.

Change History

12/27/07 16:43:11 changed by fabien

  • qualification set to Unreviewed.
  • milestone set to 1.0.11.

12/27/07 16:45:12 changed by fabien

  • status changed from new to closed.
  • resolution set to fixed.

in r6761 and r6762