1

I am having trouble with Chrome and the name Chrome gives a PDF on download.

The button: Chrome PDF Download Button

The file name as read by Chrome: PDF Name

The name of the file when I click the download button: ControlFile.php

I have narrowed it down to an issue with Chrome PDF Viewer. Altering the headers and URL bar have no effect. If I disable the plugin, it downloads with the correct name.

I have been unable to find a way to change the name that gets generated. Is anyone able to assist me in this?

As requested, here is the code where the content is being named:

header('content-type:application/pdf');
header('Content-Disposition: inline; filename='.$name . '.' . $format);
echo $output;

I checked the headers before the echo using headers_list(). The issue is only for displaying PDFs on screen and downloading them using the button that appears in chrome, not for when downloading without displaying.

dabuda
  • 101
  • 1
  • 2
  • 12
  • please show your code where you name the document – cmorrissey Sep 16 '16 at 19:30
  • There is a header for that: http://stackoverflow.com/questions/13307499/http-download-file-name – Christian Sep 17 '16 at 07:08
  • 1
    @Christian - that SO answer forces the document to download. OP is using disposition inline not attachment, which is what you send if you want the content to render in the browser and are offering a filename only if the user wants to download the content. Chrome 62 doesn't have a problem with the OP's code, so it must have been fixed somewhere along the line over the past year. – Peter Brand Nov 30 '17 at 12:40

2 Answers2

1

Just add the filename to end of URL, it works fine for me

ex:

ControlFile.php/Myfilename.pdf

Rick31
  • 89
  • 12
  • If you use NGinx, mind sharing the rule you used to make that point to ControlFile.php like that? – Floss May 14 '19 at 18:17
0

I think you've missed the quotes and the type of the content (attachment):

header('Content-Disposition: attachment; filename="'.$name . '.' . $format.'"');
Marcos Pérez Gude
  • 21,869
  • 4
  • 38
  • 69
  • Not quite. The attachment content-disposition asks them to download the PDF, and I have that at another section of code. The file name when downloading like that displays correctly. It is only when they want to view the file before saving that the issue occurs. – dabuda Sep 19 '16 at 14:26
  • If visitors see the file before saving, what kind of filename you need? They are seeing a webpage, not a file. – Marcos Pérez Gude Sep 19 '16 at 14:34
  • They are seeing a PDF on a webpage. The filename gets read correctly (see above image, it is displayed on the page by Chrome PDF Viewer). When the download button is pressed, the name and extension are lost, and it attempts to save as mainline.php. This is only an issue for Chrome. IE and FireFox do the exact same thing, only correctly. – dabuda Sep 19 '16 at 14:54