I realized that the $name variable defined in file_get_content_headers (file.inc) is not used in the array returned by the function. I was trying to find out why the files that I downloaded to a private directory were being downloaded with "no name", yet the download uri displayed the name perfectly.
After adding this line to the array of headers returned by the refered function, the download now works perfectly:
'Content-Disposition' => "attachment; filename=\"$name\"",
The function now is like this:
function file_get_content_headers($file) {
$name = mime_header_encode($file->filename);
$type = mime_header_encode($file->filemime);
return array(
'Content-Type' => $type,
'Content-Disposition' => "attachment; filename=\"$name\"",
'Content-Length' => $file->filesize,
'Cache-Control' => 'private',
);
}
Any comments on this are welcome.
Thanks.
Comments
Comment #1
neRok commentedI found this related issue #1773032: Non-standard and pointless name attribute added to Content-Type header
Comment #2
mrtcstcstcs commentedFor some reason after upgrading to the latest drupal core the bug was 'fixed' although my "fix" was not incorporated and the function was exactly as before.
Comment #3
chi commentedThe variable is still unused.
Comment #4
hgoto commentedComment #5
David_Rothstein commentedThis was fixed in #2853160: Variable $name is defined but not used in file_get_content_headers().
(That issue is newer, but this one never had a patch.)
Comment #6
David_Rothstein commentedActually, it seems this issue is recommending something different.