As the filename is not passed to the header in

function private_download_file_download($filepath) {
  $header = array('Content-Type: '. file_get_mimetype($filepath), 'Content-Length: '. filesize(file_create_path($filepath)));
  // add additional file header attributes
  return array_merge($header, explode("\n", variable_get('private_download_header', "Content-Transfer-Encoding: binary\nCache-Control: max-age=60, must-revalidate")));
}

browsers like Firefox don't display a filename in their "Opening" dialog when downloading a file. Also the application opening the file on the client displays a strange partially random filename like e.g. kt0aXIXi.pdf-1.part as the name of the downloaded and opened file.

This can be avoided (at least in my case on 2 different servers) by setting Content-Disposition additionally like in

  $header = array('Content-Type: '. file_get_mimetype($filepath), 
                   'Content-Length: '. filesize(file_create_path($filepath)),
                   'Content-Disposition: attachment; filename="'. basename($filepath).'"');

Comments

richardmetzger’s picture

I've learned that instead of
Content-Disposition: attachment; filename="'. basename($filepath).'"'
it would be better to use
Content-Disposition: attachment; filename="'. mime_header_encode(basename($filepath)).'"'

johnhanley’s picture

@richardmetzger,

Thanks for your original post and follow-up. I'll be sure to include your suggestion in the next release, which hopefully we be within the next week or two.

John (aka. Bacteria Man)

johnhanley’s picture

Status: Active » Closed (fixed)

This fix has been applied to the dev version and will be part of the next release. Thanks!