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.
On line 87 there is a call to mime_content_type which is a depreciated function, and therefore does not exist on many installs. When it is called on newer versions of PHP it will return a fatal error.
The solution is to check if the function exists before using the function:
if (function_exists('mime_content_type')) {
$mime_type = 'Content-Type:'.mime_content_type($filepath);
}
else {
$mime_type = NULL;
}
return array(
$mime_type,
'Content-Disposition: attachment; filename="' . basename($filepath) . '";',
// Content-Length is also a good header to send, as it allows the browser to
// display a progress bar correctly.
// There's a trick for determining the file size for files over 2 GB. Nobody
// should be using this module with files that large, but… the sprintf()
// trickery makes sure the value is correct for files larger than 2GB. See
// note at http://php.net/filesize
'Content-Length: ' . sprintf('%u', filesize($filepath)),
);
I tested the above code and it works.
Comments
Comment #1
arski CreditAttribution: arski commentedThanks,
Any ideas of an alternative solution though? Would still like to have the mime type sent back when forcing the download..
Comment #2
arski CreditAttribution: arski commentedOK, fixed using an alternative from http://www.php.net/manual/en/function.finfo-file.php in PHP 5.3, and mime_content_type if that doesn't exist.. should cover all cases.. if not then you're out of luck ;)
Thanks for reporting.