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

neRok’s picture

Version: 7.22 » 7.x-dev
mrtcstcstcs’s picture

Version: 7.x-dev » 7.23
Issue summary: View changes
Status: Active » Closed (cannot reproduce)

For 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.

Chi’s picture

Version: 7.23 » 7.x-dev
Status: Closed (cannot reproduce) » Active

The variable is still unused.

hgoto’s picture

David_Rothstein’s picture

Status: Active » Closed (duplicate)

This 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.)

David_Rothstein’s picture

Title: File header dont use variable $name therefore download comes with "no name". » file_get_content_headers should add a Content-Disposition header with "filename" in it
Status: Closed (duplicate) » Active

Actually, it seems this issue is recommending something different.