Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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 CreditAttribution: neRok commentedI found this related issue #1773032: Non-standard and pointless name attribute added to Content-Type header
Comment #2
mrtcstcstcs CreditAttribution: 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 CreditAttribution: Chi commentedThe variable is still unused.
Comment #4
hgoto CreditAttribution: hgoto as a volunteer commentedComment #5
David_Rothstein CreditAttribution: David_Rothstein as a volunteer 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 CreditAttribution: David_Rothstein as a volunteer commentedActually, it seems this issue is recommending something different.